#include <bits/stdc++.h>
using namespace std;
int s[100005], head = 1, tail;
int c, n, a[100005];
long long f[100005], tot;
int main() {
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    tot += a[i];
    while (head <= tail && s[head] <= i - c) head++;
    while (head <= tail && a[s[tail]] > a[i]) tail--;
    s[++tail] = i;
    if (i >= c) f[i] = f[i - c] + a[s[head]];
    f[i] = max(f[i - 1], f[i]);
  }
  cout << tot - f[n] << endl;
  return 0;
}
