#include <bits/stdc++.h>
using namespace std;
long long dp[100005];
int n;
long long a[100005];
long long sum[100005];
long long f(int i, int c) {
  if (i == n - c) {
    return sum[i];
  }
  if (i == n - 1) {
    return a[i];
  }
  if (dp[i] != -1) {
    return dp[i];
  }
  if (i > n - c) {
    return dp[i] = f(i + 1, c) + a[i];
  }
  return dp[i] = min(f(i + 1, c) + a[i], f(i + c, c) + sum[i]);
}
int main() {
  int c;
  cin >> n >> c;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  };
  if (c > n) {
    long long sumi = 0;
    for (long long i = 0; i < n; i++) {
      sumi += a[i];
    }
    cout << sumi << endl;
    return 0;
  }
  memset(dp, -1, sizeof dp);
  multiset<long long> xx;
  long long sm = 0;
  for (long long i = 0; i < c; i++) {
    sm += a[i];
    xx.insert(a[i]);
  }
  sum[0] = sm - *(xx.begin());
  for (long long i = c; i < n; i++) {
    sm += a[i];
    sm -= a[i - c];
    xx.insert(a[i]);
    xx.erase(xx.find(a[i - c]));
    sum[i - c + 1] = sm - *(xx.begin());
  }
  cout << f(0, c);
}
