#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long a[N];
int n, c;
long long mi[N];
long long f[N];
long long bl[N];
int blk;
void initblk() {
  blk = pow(n, 0.666);
  memset(mi, 0x3f, sizeof(mi));
  for (int i = 1; i <= n; ++i) {
    bl[i] = (i - 1) / blk + 1;
    mi[bl[i]] = min(mi[bl[i]], a[i]);
  }
}
long long getmi(int l, int r) {
  int k1 = bl[l], k2 = bl[r];
  long long mii = 1e18;
  if (k1 == k2) {
    for (int i = l; i <= r; ++i) {
      mii = min(mii, a[i]);
    }
  } else {
    for (int i = l; i <= k1 * blk; ++i) {
      mii = min(mii, a[i]);
    }
    for (int i = k1 + 1; i <= k2 - 1; ++i) {
      mii = min(mii, mi[i]);
    }
    for (int i = (k2 - 1) * blk + 1; i <= r; ++i) {
      mii = min(mii, a[i]);
    }
  }
  return mii;
}
void solve() {
  cin >> n >> c;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  initblk();
  for (int i = c; i <= n; ++i) {
    f[i] = max(f[i - 1], f[i - c] + getmi(i - c + 1, i));
  }
  cout << sum - f[n] << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
