#include <bits/stdc++.h>
using namespace std;
const int Nmax = 100005;
int v[Nmax];
int n, k, lsh, rsh;
long long dp[Nmax];
long long sum[Nmax];
int SegmentTree[4 * Nmax];
void build(int p, int q, int node) {
  if (p == q) {
    SegmentTree[node] = v[p];
  } else {
    int mid = (p + q) >> 1;
    build(p, mid, (node << 1));
    build(mid + 1, q, ((node << 1) + 1));
    SegmentTree[node] =
        min(SegmentTree[(node << 1)], SegmentTree[((node << 1) + 1)]);
  }
}
int query(int p, int q, int node) {
  if (lsh <= p and q <= rsh) {
    return SegmentTree[node];
  } else {
    int mid = (p + q) >> 1;
    int m1 = INT_MAX, m2 = INT_MAX;
    if (lsh <= mid) m1 = query(p, mid, (node << 1));
    if (mid < rsh) m2 = query(mid + 1, q, ((node << 1) + 1));
    return min(m1, m2);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> v[i];
  build(1, n, 1);
  for (int i = 1; i < k; i++) {
    sum[i] = v[i] + sum[i - 1];
    dp[i] = sum[i];
  }
  for (int i = k; i <= n; i++) {
    sum[i] = v[i] + sum[i - 1];
    lsh = i - k + 1;
    rsh = i;
    dp[i] =
        min(dp[i - 1] + v[i], dp[i - k] + sum[i] - sum[i - k] - query(1, n, 1));
  }
  cout << dp[n];
  return 0;
}
