#include <bits/stdc++.h>
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
using namespace std;
long long dp[MAXN];
long long a[MAXN];
long long sum[MAXN];
deque<pair<int, int> > q;
int main() {
  int n, c;
  scanf("%d %d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1] + a[i];
    while (q.size()) {
      pair<int, int> x = q.back();
      if (a[i] <= x.first) {
        q.pop_back();
      } else
        break;
    }
    q.push_back({a[i], i});
    while (q.size()) {
      pair<int, int> x = q.front();
      if (i - x.second >= c) {
        q.pop_front();
      } else
        break;
    }
    if (i >= c) {
      dp[i] = min(dp[i], dp[i - c] + sum[i] - sum[i - c] - q.front().first);
    }
  }
  cout << dp[n] << endl;
  return 0;
}
