#include <bits/stdc++.h>
using namespace std;
int n, c;
int ai[100010];
int Left[300000], Right[300000];
int n2;
int Tree[300000];
long long memo[100010];
void addTree(int ii, int vv) {
  int i = n2 + ii;
  Tree[i] = vv;
  i /= 2;
  while (i >= 1) {
    if (Tree[2 * i] < Tree[2 * i + 1])
      Tree[i] = Tree[2 * i];
    else
      Tree[i] = Tree[2 * i + 1];
    i /= 2;
  }
}
int srch(int nd, int ll, int rr) {
  if (Left[nd] >= ll && Right[nd] <= rr) return Tree[nd];
  if (Left[nd] > rr || Right[nd] < ll) return 2000000000;
  return min(srch(2 * nd, ll, rr), srch(2 * nd + 1, ll, rr));
}
int getTree(int ll, int rr) { return srch(1, ll, rr); }
void solve() {
  int i;
  n2 = 1;
  while (n2 < n) n2 *= 2;
  for (i = 0; i < n2; i++) Left[n2 + i] = Right[n2 + i] = i;
  for (i = n2 - 1; i >= 1; i--) {
    Left[i] = Left[2 * i];
    Right[i] = Right[2 * i + 1];
  }
  for (i = 0; i < n; i++) addTree(i, ai[i]);
  for (; i < n2; i++) addTree(i, 2000000000);
  memo[n] = 0;
  for (i = n - 1; i > n - c && i >= 0; i--) memo[i] = 0;
  long long tmp;
  for (; i >= 0; i--) {
    tmp = memo[i + c] + getTree(i, i + c - 1);
    if (tmp < memo[i + 1]) tmp = memo[i + 1];
    memo[i] = tmp;
  }
  long long sum = 0;
  for (i = 0; i < n; i++) sum += ai[i];
  printf("%I64d\n", sum - memo[0]);
}
int main() {
  int i;
  scanf("%d%d", &n, &c);
  for (i = 0; i < n; i++) scanf("%d", &ai[i]);
  solve();
  return 0;
}
