#include <bits/stdc++.h>
using namespace std;
int n, c;
vector<long long> a;
int main() {
  cin >> n >> c;
  a = vector<long long>(n + 1, 0);
  long long sum = 0;
  for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
  multiset<long long> g;
  vector<long long> dp(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1];
    g.insert(a[i]);
    if (i - c > 0) g.erase(g.find(a[i - c]));
    if (i >= c) {
      dp[i] = max(dp[i], dp[i - c] + (*g.begin()));
    }
  }
  cout << sum - dp[n] << endl;
  return 0;
}
