#include <bits/stdc++.h>
using namespace std;
long long n, c;
vector<long long> a(100000 + 2);
vector<long long> pre(100000 + 2, 0);
vector<long long> ans(100000 + 2, 0);
vector<long long> memo(100000 + 2, -1);
long long solve(long long i) {
  if (i > n) return 0;
  if (memo[i] != -1) return memo[i];
  if (i + c - 1 > n) {
    return memo[i] = a[i] + solve(i + 1);
  }
  return memo[i] = min(a[i] + solve(i + 1),
                       pre[i + c - 1] - pre[i - 1] - ans[i] + solve(i + c));
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  set<pair<long long, long long> > s;
  long long i;
  cin >> n >> c;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = pre[i - 1] + a[i];
  }
  for (i = 1; i <= min(c, n); i++) {
    s.insert({a[i], i});
  }
  ans[1] = (*s.begin()).first;
  for (i = c + 1; i <= n; i++) {
    s.erase({a[i - c], i - c});
    s.insert({a[i], i});
    ans[i - c + 1] = (*s.begin()).first;
  }
  cout << solve(1);
  return 0;
}
