#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, c;
int a[N];
int pos[N], bl;
long long s[N];
int mn[N << 2];
long long f[N];
void build(int pos, int L, int R) {
  if (L == R) {
    mn[pos] = a[L];
    return;
  }
  int mid = (L + R) >> 1;
  build(pos << 1, L, mid);
  build(pos << 1 | 1, mid + 1, R);
  mn[pos] = min(mn[pos << 1], mn[pos << 1 | 1]);
}
int query(int pos, int L, int R, int ll, int rr) {
  if (ll > R || L > rr) return 0x3f3f3f3f;
  if (ll <= L && rr >= R) return mn[pos];
  int mid = (L + R) >> 1;
  return min(query(pos << 1, L, mid, ll, rr),
             query(pos << 1 | 1, mid + 1, R, ll, rr));
}
int main() {
  scanf("%d%d", &n, &c);
  bl = c;
  for (int i = 1; i <= n; ++i) pos[i] = i / bl + 1;
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
  build(1, 1, n);
  if (n < c) {
    printf("%I64d\n", s[n]);
    return 0;
  }
  if (n == c) {
    printf("%I64d\n", s[n] - query(1, 1, n, 1, n));
    return 0;
  }
  long long ans = s[n];
  for (int i = c; i <= n; ++i)
    f[i] = max(f[i - 1], f[i - c] + query(1, 1, n, i - c + 1, i));
  cout << ans - f[n];
  return 0;
}
