#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 2e5 + 4;
long long dp[N];
long long st[4 * N];
long long a[N];
void build(long long node, long long L, long long R) {
  if (L == R) {
    st[node] = a[L];
    return;
  }
  long long M = (L + R) / 2;
  build(node * 2, L, M);
  build(node * 2 + 1, M + 1, R);
  st[node] = min(st[node * 2], st[node * 2 + 1]);
}
long long query(long long node, long long L, long long R, long long i,
                long long j) {
  if (j < L || i > R) return 1e10;
  if (i <= L && R <= j) return st[node];
  long long M = (L + R) / 2;
  long long left = query(node * 2, L, M, i, j);
  long long right = query(node * 2 + 1, M + 1, R, i, j);
  return min(left, right);
}
long long n, c;
long long pre[N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> c;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    pre[i] = pre[i - 1] + a[i];
  }
  build(1, 1, n);
  for (long long i = 1; i <= n; i++) {
    dp[i] = dp[i - 1] + a[i];
    if (i - c == 0) {
      dp[i] = min(dp[i], pre[c] - query(1, 1, n, 1, c));
    } else if (i - c > 0) {
      dp[i] = min(dp[i], dp[i - c] + pre[i] - pre[i - c] -
                             query(1, 1, n, i - c + 1, i));
    }
  }
  cout << dp[n] << endl;
}
