#include <bits/stdc++.h>
using namespace std;
long long dp[100010];
deque<int> mi;
int a[100010];
int mia[100010];
long long sum[100010];
int main() {
  int n, c;
  scanf("%d %d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
    while (mi.size() && a[i] <= a[mi.back()]) mi.pop_back();
    mi.push_back(i);
    while (mi.size() && i - mi.front() >= c) mi.pop_front();
    mia[i] = a[mi.front()];
  }
  long long tmp = sum[n];
  for (int i = 1; i <= n; i++) {
    dp[i] = tmp - (sum[n] - sum[i]);
    if (i >= c) {
      dp[i] = min(dp[i], dp[i - c] + sum[i] - sum[i - c] - mia[i]);
    }
    tmp = min(dp[i] + sum[n] - sum[i], tmp);
  }
  printf("%lld", dp[n]);
  return 0;
}
