#include <bits/stdc++.h>
using namespace std;
int a[100005];
long long sum[100005];
long long dp[100005];
int st[4 * 100005];
void build(int n, int s, int e) {
  if (s == e)
    st[n] = a[s];
  else {
    int mid = (s + e) / 2;
    build(n * 2, s, mid);
    build(n * 2 + 1, mid + 1, e);
    st[n] = min(st[n * 2], st[n * 2 + 1]);
  }
}
int query(int n, int s, int e, int l, int r) {
  if (s > r || l > e) return 1e9;
  if (l <= s && e <= r) return st[n];
  int mid = (s + e) / 2;
  return min(query(n * 2, s, mid, l, r), query(n * 2 + 1, mid + 1, e, l, r));
}
int main() {
  int n, c;
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), dp[i] = 1e18, sum[i] = sum[i - 1] + a[i];
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    dp[i] = min(dp[i], dp[i - 1] + a[i]);
    if (i + c - 1 <= n) {
      dp[i + c - 1] =
          min(dp[i + c - 1], dp[i - 1] + sum[i + c - 1] - sum[i - 1] -
                                 query(1, 1, n, i, i + c - 1));
    }
  }
  printf("%lld\n", dp[n]);
}
