#include <bits/stdc++.h>
using namespace std;
int tree[500000], n, c, ara[300000];
long long dp[300000], ldp[300000];
void update(int node, int st, int en, int l, int v) {
  if (st > l or en < l) return;
  if (st == en) {
    tree[node] = v;
    return;
  }
  int mid = (st + en) / 2;
  update(node * 2, st, mid, l, v);
  update(node * 2 + 1, mid + 1, en, l, v);
  tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
}
int query(int node, int st, int en, int l, int r) {
  if (st > r or en < l) return (2147483647);
  if (st >= l and en <= r) return tree[node];
  int mid = (st + en) / 2;
  int p = query(node * 2, st, mid, l, r);
  int q = query(node * 2 + 1, mid + 1, en, l, r);
  return min(p, q);
}
long long dp_func(int pos) {
  if (pos == n + 1) return 0;
  if (dp[pos] != -1) return dp[pos];
  long long ret = (1LL << 55);
  ret = dp_func(pos + 1) + ara[pos];
  if ((pos + c - 1) <= n) {
    ret = min(ret, dp_func(pos + c) + (ldp[pos + c - 1] - ldp[pos - 1]) -
                       query(1, 1, n, pos, c + pos - 1));
  }
  return dp[pos] = ret;
}
int main() {
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; i++) {
    int l;
    scanf("%d", &l);
    ara[i] = l;
    ldp[i] = ldp[i - 1] + ara[i];
    update(1, 1, n, i, l);
  }
  memset(dp, -1, sizeof dp);
  long long ret = dp_func(1);
  cout << ret << endl;
}
