#include <bits/stdc++.h>
using namespace std;
int n, c;
long long a[100005], dp[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  deque<long long> q;
  long long s = 0;
  for (int i = 0; i < n; i++) {
    dp[i + 1] = dp[i] + a[i];
    s += a[i];
    while (!q.empty() && q.back() > a[i]) q.pop_back();
    q.push_back(a[i]);
    if (i + 1 >= c + 1) {
      if (q.front() == a[i - c]) q.pop_front();
      s -= a[i - c];
    }
    if (i + 1 >= c) dp[i + 1] = min(dp[i + 1], dp[i + 1 - c] + s - q.front());
  }
  cout << dp[n];
  return 0;
}
