#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, k;
long long a[N], f[N], ss;
multiset<long long> s;
int main() {
  scanf("%d%d", &n, &k);
  for (int i(1); i <= (n); ++i) scanf("%lld", a + i);
  for (int i(1); i <= (n); ++i) {
    f[i] = f[i - 1] + a[i];
    s.insert(a[i]);
    ss += a[i];
    if (i > k) s.erase(s.find(a[i - k])), ss -= a[i - k];
    if (i >= k) f[i] = min(f[i], f[i - k] + ss - *s.begin());
  }
  printf("%lld\n", f[n]);
  return 0;
}
