#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
inline int in() {
  char ch = getchar();
  int f = 1, tmp = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    tmp = (tmp << 1) + (tmp << 3) + (ch - '0');
    ch = getchar();
  }
  return tmp * f;
}
const int N = 100010;
long long n, c, a[2 * N];
long long f[N][20], lo[N];
long long g[N];
int gi_f(int l, int r) {
  int x = lo[r - l + 1];
  return min(f[l][x], f[r - (1 << x) + 1][x]);
}
int main() {
  n = in(), c = in();
  memset(f, 0x3f, sizeof(f));
  for (int i = 1; i <= n; i++) a[i] = in(), f[i][0] = a[i];
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      f[i][j] = min(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]);
  for (int i = 2; i <= n; i++) lo[i] = lo[i >> 1] + 1;
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += a[i];
  for (int i = c; i <= n; i++)
    g[i] = max(g[i - 1], g[i - c] + gi_f(i - c + 1, i));
  cout << ans - g[n] << endl;
  return 0;
}
