#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long dp[N], s[N], a[N];
multiset<long long> mst;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i] = s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i < c; i++) mst.insert(a[i]);
  for (int i = c; i <= n; i++) {
    mst.insert(a[i]);
    dp[i] = min(dp[i - 1] + a[i], dp[i - c] + s[i] - s[i - c] - *mst.begin());
    mst.erase(mst.find(a[i - c + 1]));
  }
  cout << dp[n] << endl;
  return 0;
}
