#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <math.h>
#include <vector>
#include <set>
#include <map>
using namespace std;
long long a[100001];
int main() {
int n, k, p;
long long s, sum, ans = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
ans += a[i];
}
p = 0;
s = ans;
while (p < n) {
sum = 0;
for (int i = 0; i < n && p + (i * k) < n; i++) {
sum += a[p + (i * k)];
}
sum = s - sum;
ans = min(ans, sum);
p++;
}
cout << ans;
return 0;
}