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