#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, d;
long long a[N] = {};
long long f[N] = {};
long long ans[N] = {};
multiset<long long> s;
long long get(int i) {
  if (i < 0) return 0;
  long long res = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) {
    res = max(res, f[i]);
  }
  return res;
}
void upd(int i, long long val) {
  for (; i < N; i |= i + 1) {
    f[i] = max(f[i], val);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> d;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    if (i < d) s.insert(a[i]);
  }
  if (n >= d) ans[0] = *(s.begin());
  for (int i = d; i < n; i++) {
    s.erase(s.find(a[i - d]));
    s.insert(a[i]);
    ans[i - d + 1] = *(s.begin());
  }
  for (int i = 0; i < n; i++) {
    upd(i, get(i - d) + ans[i]);
  }
  long long mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, get(i));
  }
  cout << sum - mx;
  return 0;
}
