#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  x = 0;
  char c;
  int sign = 1;
  do {
    c = getchar();
    if (c == '-') sign = -1;
  } while (!isdigit(c));
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (isdigit(c));
  x *= sign;
}
const int N = 1e5 + 500;
const long long inf = 1e18;
int a[N], n, c;
long long f[N], sum[N], ans;
int q[N], st, en, t;
int main() {
  read(n);
  read(c);
  for (register int i = 1; i <= n; ++i) read(a[i]), sum[i] = sum[i - 1] + a[i];
  st = 1;
  for (register int i = 1; i <= c; ++i) {
    while (st <= en && a[q[en]] > a[i]) en--;
    while (st <= en && i - q[st] >= c) st++;
    q[++en] = i;
    f[i] = sum[i];
  }
  ans = sum[n];
  f[c] = sum[c] - a[q[st]];
  if (n >= c) ans = min(ans, f[c] + sum[n] - sum[c]);
  for (register int i = c + 1; i <= n; ++i) {
    while (st <= en && a[q[en]] > a[i]) en--;
    while (st <= en && i - q[st] >= c) st++;
    q[++en] = i;
    if (f[i - c] - f[t] < sum[i - c] - sum[t]) t = i - c;
    f[i] = sum[i] - sum[t] + f[t] - a[q[st]];
    ans = min(ans, f[i] + sum[n] - sum[i]);
  }
  cout << ans << endl;
  return 0;
}
