#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const long long inf = 0x3f3f3f3f3f3f3f;
long long n, c;
multiset<long long> s;
long long a[maxn], sum[maxn], dp[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] += sum[i - 1] + a[i];
  }
  if (c == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (c > n) {
    cout << sum[n] << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (i < c) {
      dp[i] = dp[i - 1] + a[i];
      s.insert(a[i]);
    } else {
      s.insert(a[i]);
      if (i > c) s.erase(s.find(a[i - c]));
      long long m = *s.begin();
      dp[i] = min(dp[i - 1] + a[i], dp[i - c] - m + sum[i] - sum[i - c]);
    }
  }
  cout << dp[n] << endl;
}
