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