#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = 0;
  while (!isdigit(c = getchar())) f -= (c == '-') * 2;
  while (isdigit(c)) {
    x = x * 10 + f * (c - 48);
    c = getchar();
  }
  return x;
}
struct node {
  long long s;
  long long k;
};
long long a[100001], tot[100001], g[100001], dp[100001];
long long c, n, st, ed, ans;
node que[100001];
signed main() {
  register long long i, j;
  n = read();
  c = read();
  for (i = 1; i <= n; ++i) a[i] = read();
  for (i = 1; i <= n; ++i) tot[i] = a[i] + tot[i - 1];
  for (i = 1; i <= n; ++i) {
    while (st > ed && a[i] < que[st - 1].s) --st;
    que[st].k = i;
    que[st].s = a[i];
    ++st;
    while (ed < st && que[ed].k <= i - c) ++ed;
    g[i] = que[ed].s;
  }
  for (i = 1; i < c; ++i) dp[i] = a[i] + dp[i - 1];
  for (i = c; i <= n; ++i)
    dp[i] = min(dp[i - 1] + a[i], dp[i - c] + tot[i] - g[i] - tot[i - c]);
  cout << dp[n] << endl;
  return 0;
}
