#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void solve() {
int n, k;
cin >> n >> k;
vector<int> v(n);
for (auto &x : v) {
cin >> x;
}
ll sum = accumulate(v.begin(), v.end(), 0LL);
ll ans = 1e18;
for (int i = 0; i < k; i++) {
int j = i;
ll cur = 0;
while (j < n) {
cur += v[j];
j += k;
}
ans = min(ans, sum - cur);
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}