#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, c;
  cin >> n >> c;
  long long a[n + 1], pre[n + 1], dp[n + 1], pre1[n + 1];
  multiset<long long> st;
  map<pair<long long, long long>, long long> mp, mp1;
  memset(dp, 0, sizeof(dp));
  memset(pre, 0, sizeof(pre));
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = a[i] + pre[i - 1];
  }
  if (c <= n) {
    long long l = 1, r = c;
    for (long long i = 1; i <= c; i++) {
      st.insert(a[i]);
    }
    mp1[{1, c}] = *st.begin();
    r++;
    l++;
    while (r <= n) {
      st.erase(st.find(a[l - 1]));
      st.insert(a[r]);
      mp1[{l, r}] = *st.begin();
      l++;
      r++;
    }
  }
  for (long long i = 1; i <= n; i++) {
    if (i + c - 1 <= n) {
      mp[{i, i + c - 1}] = pre[i + c - 1] - pre[i - 1];
    }
  }
  for (long long i = 1; i <= n; i++) {
    dp[i] = dp[i - 1] + a[i];
    if (i - c + 1 >= 1) {
      dp[i] =
          min(dp[i], dp[i - c] + (mp[{i - c + 1, i}] - mp1[{i - c + 1, i}]));
    }
  }
  cout << dp[n] << '\n';
  return 0;
}
