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