#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, c;
  cin >> n >> c;
  vector<long long> a(n);
  vector<long long> sm(c);
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  vector<long long> dp(n);
  multiset<long long> hv;
  for (long long i = 0; i < min(n, c - 1); i++) {
    hv.insert(a[i]);
  }
  for (long long i = c - 1; i < n; i++) {
    hv.insert(a[i]);
    if (i > 0) dp[i] = dp[i - 1];
    if ((long long)hv.size() == c) {
      long long v = 0;
      if (i >= c) v = dp[i - c];
      dp[i] = max(dp[i], v + *hv.begin());
    }
    hv.erase(hv.find(a[i - c + 1]));
  }
  cout << ans - dp.back() << endl;
}
