#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long num = 0;
  bool flag = 1;
  char c = getchar();
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') flag = 0;
  for (; c >= '0' && c <= '9'; c = getchar())
    num = (num << 1) + (num << 3) + c - '0';
  return flag ? num : -num;
}
const long long N = 1e5 + 10;
long long n, k, a[N], f[N], Min[N], sum;
priority_queue<long long> Max;
signed main() {
  n = read();
  k = read();
  for (long long i = 1; i <= n; i++) a[i] = read(), sum += a[i];
  long long h = 1, t = 0;
  for (long long i = 1; i < k; i++) {
    while (h <= t && a[Min[t]] >= a[i]) t--;
    Min[++t] = i;
  }
  for (long long i = k; i <= n; i++) {
    Max.push(f[i - k]);
    while (h <= t && Min[h] < i - k + 1) h++;
    while (h <= t && a[Min[t]] >= a[i]) t--;
    Min[++t] = i;
    f[i] = Max.top() + a[Min[h]];
  }
  long long maxx = 0;
  for (long long i = n - k + 1; i <= n; i++) maxx = max(maxx, f[i]);
  printf("%lld", sum - maxx);
  return 0;
}
