#include <bits/stdc++.h>
using namespace std;
multiset<pair<int64_t, int64_t> > s;
const int64_t N = 1e5 + 9;
int64_t a[N], dp[N], sum[N], n, c;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> c;
  for (int64_t i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  if (n < c) {
    cout << sum[n] << '\n';
    return 0;
  }
  for (int64_t i = n - c + 2; i <= n; i++)
    s.insert(make_pair(a[i], i)), dp[i] = sum[n] - sum[i - 1];
  for (int64_t i = n - c + 1; i; i--) {
    s.insert(make_pair(a[i], i));
    int64_t mn;
    while (s.begin()->second > i + c - 1) s.erase(s.begin());
    int64_t t = s.begin()->first;
    int64_t fa = dp[i + c] + sum[i + c - 1] - sum[i - 1] - t;
    int64_t sa = dp[i + 1] + a[i];
    dp[i] = min(fa, sa);
  }
  cout << dp[1] << '\n';
}
