#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
long long int arr[maxn];
long long int dp[maxn];
long long int sum[maxn];
multiset<int> s1;
void solve() {
  int n, c;
  scanf("%d", &n);
  scanf("%d", &c);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
    sum[i] = sum[i - 1] + arr[i];
  }
  for (int i = 1; i <= n; i++) {
    if (i > c) {
      s1.erase(s1.find(arr[i - c]));
    }
    s1.insert(arr[i]);
    if (i < c) {
      dp[i] = sum[i];
    } else {
      dp[i] = min(dp[i - c] + sum[i] - sum[i - c] - (*s1.begin()),
                  dp[i - 1] + arr[i]);
    }
  }
  printf("%lld\n", dp[n]);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
