#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long dp[N], sum[N], a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, c;
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  deque<long long> q;
  for (int i = 1; i <= min(n, c - 1); i++) {
    dp[i] = sum[i];
    while (q.size() > 0) {
      if (a[q.back()] >= a[i]) {
        q.pop_back();
      } else
        break;
    }
    q.push_back(i);
  }
  long long ans = sum[n];
  for (int i = c; i <= n; i++) {
    while (q.size() > 0 && q.front() <= (i - c)) q.pop_front();
    while (q.size() > 0) {
      if (a[q.back()] >= a[i]) {
        q.pop_back();
      } else
        break;
    }
    q.push_back(i);
    dp[i] = dp[i - 1] + a[i];
    dp[i] = min(dp[i], dp[i - c] + sum[i] - sum[i - c] - a[q.front()]);
    ans = min(ans, dp[i] + sum[n] - sum[i]);
  }
  cout << ans;
}
