#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long tree[400001];
void build(long long i, long long st, long long en) {
  if (st == en) {
    tree[i] = v[st];
  } else {
    long long mid = st + (en - st) / 2;
    build(2 * i, st, mid);
    build(2 * i + 1, mid + 1, en);
    tree[i] = min(tree[2 * i], tree[2 * i + 1]);
  }
}
long long query(long long i, long long st, long long en, long long l,
                long long r) {
  if (l > en || r < st)
    return 100000000000;
  else if (l <= st && r >= en)
    return tree[i];
  else {
    long long mid = st + (en - st) / 2;
    long long p1 = query(2 * i, st, mid, l, r);
    long long p2 = query(2 * i + 1, mid + 1, en, l, r);
    return min(p1, p2);
  }
}
int main() {
  long long n, c, num;
  cin >> n >> c;
  vector<long long> pref;
  for (long long i = 0; i < n; i++) {
    cin >> num;
    v.push_back(num);
  }
  pref.push_back(v[0]);
  for (long long i = 1; i < n; i++) {
    pref.push_back(pref[i - 1] + v[i]);
  }
  if (c == 1)
    cout << 0;
  else {
    long long dp[n];
    for (long long i = 0; i < n; i++) dp[i] = 0;
    dp[0] = v[0];
    build(1, 0, n - 1);
    for (long long i = 1; i < n; i++) {
      if (i + 1 >= c) {
        if (i - c >= 0) dp[i] = dp[i - c];
        long long s = pref[i];
        if (i - c >= 0) s -= pref[i - c];
        dp[i] += s - query(1, 0, n - 1, i - c + 1, i);
        dp[i] = min(dp[i], dp[i - 1] + v[i]);
      } else
        dp[i] = dp[i - 1] + v[i];
    }
    cout << dp[n - 1];
  }
}
