#include <bits/stdc++.h>
using namespace std;
long long a[100005], n, c, mn[100005], dp[200005], sum;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> c;
  for (int i = 0; i < n; sum += a[i++]) cin >> a[i];
  deque<long long> v;
  for (int i = n; i--;) {
    while (v.size() && v.back() >= i + c) v.pop_back();
    while (v.size() && a[i] <= a[v.front()]) v.pop_front();
    v.push_front(i);
    if (i <= n - c) dp[i] = max(dp[i + 1], a[v.back()] + dp[i + c]);
  }
  cout << sum - dp[0];
}
