#include <bits/stdc++.h>
using namespace std;
void tosolveornottosolve() {
  long long n, c;
  cin >> n >> c;
  vector<long long> a(n);
  for (long long& x : a) cin >> x;
  a.push_back(0);
  vector<long long> dp(n + 1);
  multiset<long long> window;
  long long windowsum = 0;
  window.insert(0);
  for (long long i = n - 1; i > -1; i--) {
    if (i + c > n) {
      dp[i] = a[i];
      if (i != n - 1) dp[i] += dp[i + 1];
      window.insert(a[i]);
      windowsum += a[i];
      continue;
    }
    windowsum -= a[i + c];
    windowsum += a[i];
    window.insert(a[i]);
    window.erase(window.find(a[i + c]));
    dp[i] = min(dp[i + 1] + a[i], dp[i + c] + windowsum - *(window.begin()));
  }
  cout << '\n' << dp[0];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  long long t = 1;
  while (t--) {
    tosolveornottosolve();
    cout << '\n';
  }
  return 0;
}
