#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100010;
const int inf = 2147483647;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
int mn[Maxn][17], a[Maxn], n, c, Log[Maxn];
int query_mn(int l, int r) {
  int t = Log[r - l + 1];
  return min(mn[l][t], mn[r - (1 << t) + 1][t]);
}
long long sum[Maxn], ans = (1LL << 60), f[Maxn];
int main() {
  n = read(), c = read();
  Log[1] = 0;
  sum[0] = 0;
  for (int i = 2; i <= n; i++) Log[i] = Log[i >> 1] + 1;
  for (int i = 1; i <= n; i++)
    a[i] = mn[i][0] = read(), sum[i] = (long long)sum[i - 1] + a[i];
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      mn[i][j] = min(mn[i][j - 1], mn[i + (1 << (j - 1))][j - 1]);
  f[0] = 0;
  for (int i = 1; i <= n; i++) {
    f[i] = f[i - 1] + a[i];
    if (i >= c)
      f[i] = min(f[i], (long long)f[i - c] + sum[i] - sum[i - c] -
                           query_mn(i - c + 1, i));
  }
  printf("%lld", f[n]);
}
