#include <bits/stdc++.h>
using namespace std;
const int maxn = 100007;
int a[maxn], n, c;
long long dp[maxn], sum[maxn];
multiset<int> st;
int main() {
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    dp[i] = sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 1; i < c; ++i) st.insert(a[i]);
  for (int i = c; i <= n; ++i) {
    st.insert(a[i]);
    dp[i] =
        min(dp[i - 1] + a[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;
}
