#include <bits/stdc++.h>
using namespace std;
int n, c;
long long a[100004];
long long p[100004];
multiset<long long> help;
long long dp[100004];
int main() {
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = a[i];
    p[i] += p[i - 1];
  }
  a[0] = 1000000000;
  help.insert(a[0]);
  for (int i = 1; i <= n; i++) {
    long long pH;
    dp[i] = dp[i - 1] + a[i];
    help.insert(a[i]);
    if (i >= c) {
      help.erase(help.find(a[i - c]));
      pH = p[i] - p[i - c];
      pH -= *help.begin();
      if (dp[i - c] + pH < dp[i]) {
        dp[i] = dp[i - c] + pH;
      }
    }
  }
  cout << dp[n];
}
