#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0;
  int zf = 1;
  char ch;
  while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') zf = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * zf;
}
void write(long long y) {
  if (y < 0) putchar('-'), y = -y;
  if (y > 9) write(y / 10);
  putchar(y % 10 + '0');
}
void printk() { puts(""); }
inline void writeln(long long x) {
  write(x);
  printk();
}
int i, j, k, m, n, x, y, z, cnt, all, num;
long long a[100010], ans[100010], res[100010];
multiset<long long> s;
int main() {
  n = read();
  k = read();
  for (register int i = 1; i <= n; i++)
    a[i] = read(), ans[i] = ans[i - 1] + a[i];
  for (register int i = 1; i <= n; i++) {
    res[i] = res[i - 1] + a[i];
    s.insert(a[i]);
    if (i > k) s.erase(s.find(a[i - k]));
    if (i >= k)
      res[i] = min(res[i], res[i - k] + ans[i] - ans[i - k] - *s.begin());
  }
  cout << res[n];
  return 0;
}
