#include <bits/stdc++.h>
using namespace std;
long long n, c, a[100001], mx[100001], dp[100001], su;
pair<long long, long long> tr[200001];
void upd(int g, int k) {
  for (tr[g += n] = make_pair(k, k); g > 1; g /= 2) {
    tr[g / 2].first = min(tr[g ^ 1].first, tr[g].first);
    tr[g / 2].second = max(tr[g ^ 1].second, tr[g].second);
  }
}
long long gei(int l, int r) {
  long long le = INT_MAX, ri = INT_MAX;
  for (l += n, r += n; l < r; l /= 2, r /= 2) {
    if (l % 2) le = min(le, tr[l++].first);
    if (r % 2) ri = min(ri, tr[--r].first);
  }
  return min(le, ri);
}
long long gex(int l, int r) {
  long long le = INT_MIN, ri = INT_MIN;
  for (l += n, r += n; l < r; l /= 2, r /= 2) {
    if (l % 2) le = max(le, tr[l++].second);
    if (r % 2) ri = max(ri, tr[--r].second);
  }
  return max(le, ri);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> c;
  su = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    su += a[i];
    upd(i, a[i]);
  }
  for (int i = c - 1; i < n; i++) {
    dp[i] += gei(i - c + 1, i + 1);
    dp[i] += mx[i - c];
    mx[i] = max(mx[i - 1], dp[i]);
  }
  cout << su - mx[n - 1] << endl;
  cout.flush();
  return 0;
}
