#include <bits/stdc++.h>
using namespace std;
long long a[100010], sum[100010], dp[100010];
int st[100010];
int main() {
  int n, c;
  scanf("%d%d", &n, &c);
  for (int i = (1); i <= (n); ++i) {
    scanf("%I64d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  if (c == 1) {
    printf("%d\n", 0);
    return 0;
  }
  dp[1] = a[1];
  int l = 0, r = 0;
  st[r++] = 1;
  for (int i = (2); i <= (n); ++i) {
    long long minn = dp[i - 1] + a[i];
    while (r > l && a[st[r - 1]] >= a[i]) --r;
    st[r++] = i;
    if (i - c >= 0) {
      while (r > l && st[l] <= i - c) ++l;
      minn = min(minn, dp[i - c] + sum[i] - sum[i - c] - a[st[l]]);
    }
    dp[i] = minn;
  }
  printf("%I64d\n", dp[n]);
  return 0;
}
