#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000000000000LL;
const int maxn = 100100;
int n, c;
long long sum[maxn], f[maxn], a[maxn], minx[4 * maxn];
inline long long getint() {
  long long ret = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
  return ret * f;
}
inline void maintain(int o) {
  int lc = o << 1, rc = o << 1 | 1;
  minx[o] = min(minx[lc], minx[rc]);
}
inline void build(int o, int l, int r) {
  if (l == r) {
    minx[o] = a[l];
    return;
  }
  int lc = o << 1, rc = o << 1 | 1, mid = l + r >> 1;
  build(lc, l, mid);
  build(rc, mid + 1, r);
  maintain(o);
}
inline long long query(int o, int l, int r, int al, int ar) {
  if (al <= l && r <= ar) return minx[o];
  int lc = o << 1, rc = o << 1 | 1, mid = l + r >> 1;
  long long ret = INF;
  if (al <= mid) ret = min(ret, query(lc, l, mid, al, ar));
  if (mid < ar) ret = min(ret, query(rc, mid + 1, r, al, ar));
  return ret;
}
int main() {
  n = getint();
  c = getint();
  for (int i = 1; i <= n; i++) sum[i] = a[i] = getint();
  for (int i = 1; i <= n; i++) sum[i] += sum[i - 1];
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    f[i] = INF;
    if (i >= c)
      f[i] = min(f[i],
                 f[i - c] + sum[i] - sum[i - c] - query(1, 1, n, i - c + 1, i));
    f[i] = min(f[i], f[i - 1] + a[i]);
  }
  printf("%I64d", f[n]);
  return 0;
}
