#include <bits/stdc++.h>
using namespace std;
const long long N = 100010;
long long a[N], dp[N], sum[N], tree[N * 4];
void build(long long node, long long l, long long r) {
  if (l == r) {
    tree[node] = a[l];
    return;
  }
  long long mid = (l + r) / 2;
  build(node * 2, l, mid);
  build(node * 2 + 1, mid + 1, r);
  tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
  return;
}
long long query(long long node, long long l, long long r, long long L,
                long long R) {
  if (l > r || r < L || l > R) return 1e18;
  if (l >= L && r <= R) return tree[node];
  long long mid = (l + r) / 2;
  long long left = query(node * 2, l, mid, L, R);
  long long right = query(node * 2 + 1, mid + 1, r, L, R);
  return min(left, right);
}
int main() {
  long long n, c, i;
  cin >> n >> c;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    dp[i] = sum[i];
  }
  build(1, 1, n);
  for (i = c; i <= n; i++)
    dp[i] = min(dp[i - 1] + a[i],
                dp[i - c] + sum[i] - sum[i - c] - query(1, 1, n, i - c + 1, i));
  cout << dp[n] << "\n";
  return 0;
}
