#include <bits/stdc++.h>
using namespace std;
const long long SIZE = 100000 + 5;
long long n, c;
long long a[SIZE], f[SIZE], sum[SIZE];
struct Segment_tree {
  long long l, r, sum;
} tree[SIZE << 2];
inline long long read() {
  char ch = getchar();
  long long f = 1, x = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void Build(long long x, long long l, long long r) {
  tree[x].l = l, tree[x].r = r;
  if (l == r) {
    tree[x].sum = a[l];
    return;
  }
  long long Mid = (l + r) >> 1;
  Build(x << 1, l, Mid);
  Build(x << 1 | 1, Mid + 1, r);
  tree[x].sum = std::min(tree[x << 1].sum, tree[x << 1 | 1].sum);
}
inline long long Query(long long x, long long l, long long r) {
  if (l <= tree[x].l && tree[x].r <= r) return tree[x].sum;
  long long Mid = (tree[x].l + tree[x].r) >> 1, ans = 2e9;
  if (l <= Mid) ans = std::min(ans, Query(x << 1, l, r));
  if (r > Mid) ans = std::min(ans, Query(x << 1 | 1, l, r));
  return ans;
}
signed main() {
  n = read(), c = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
  Build(1, 1, n);
  memset(f, 0x3f, sizeof(f));
  f[0] = 0;
  for (long long i = 1; i <= n; i++) {
    if (i >= c)
      f[i] = std::min(f[i],
                      f[i - c] + sum[i] - sum[i - c] - Query(1, i - c + 1, i));
    f[i] = std::min(f[i], f[i - 1] + a[i]);
  }
  std::cout << f[n];
  return 0;
}
