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