#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, c;
  cin >> n >> c;
  long long a[n + 1], pre[n + 1];
  memset(pre, 0, sizeof(pre));
  ;
  a[0] = 0;
  for (long long i = 0; i < n; i++)
    cin >> a[i + 1], pre[i + 1] = pre[i] + a[i + 1];
  long long dp[n + 1];
  memset(dp, 0, sizeof(dp));
  ;
  set<long long> st;
  map<long long, long long> mp;
  for (long long i = 1; i < min(c, n + 1); i++) {
    dp[i] = dp[i - 1] + a[i];
    st.insert(a[i]);
    mp[a[i]]++;
  }
  for (long long i = c; i < n + 1; i++) {
    st.insert(a[i]);
    mp[a[i]]++;
    dp[i] =
        min(dp[i - 1] + a[i], dp[i - c] + pre[i] - pre[i - c] - *st.begin());
    if (mp[a[i - c + 1]] == 1) {
      st.erase(a[i - c + 1]);
    }
    mp[a[i - c + 1]]--;
  }
  cout << dp[n];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1, i = 1;
  while (t--) {
    solve();
  }
  return 0;
}
