#include <iostream>
#include<bits/stdc++.h>
#include<unordered_map>
#define ll long long
using namespace std;
ll mn =1e18;
int main() {
std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
int k, n;cin >> n>> k;
vector<int>a(n);
ll sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
for (int i = 0; i < k; i++) {
ll cur = 0;
for (int j = i; j < n; j += k) {
cur += a[j];
}
mn = min(mn, sum - cur);
}
cout << mn;
return 0;
}