#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
long long a[200005], c[200005], d[200005], ans, s;
long long n, k;
struct tmp {
  int num;
  bool operator<(const tmp &rhs) const { return a[num] > a[rhs.num]; }
} b[200005];
priority_queue<tmp> q;
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) b[i].num = i;
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= n; i++) s += a[i];
  for (int i = 1; i <= k - 1; i++) q.push(b[i]);
  for (int i = k; i <= n; i++) {
    q.push(b[i]);
    tmp t = q.top();
    while (t.num <= i - k) q.pop(), t = q.top();
    c[i] = a[t.num];
  }
  for (int i = k; i <= n; i++) d[i] = max(d[i - 1], d[i - k] + c[i]);
  for (int i = 1; i <= n; i++) ans = max(ans, d[i]);
  cout << s - ans << "\n";
  return 0;
}
