#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 1;
int n, c, a[N];
ll sum[N], dp[N];
vector<int> mn[N];
int getMin(int l, int r) {
  int lg = 31 - __builtin_clz(r - l + 1);
  return min(mn[r][lg], mn[l + (1 << lg) - 1][lg]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    mn[i].push_back(a[i]);
    for (int j = 0; 1 << j + 1 <= i; j++)
      mn[i].push_back(min(mn[i][j], mn[i - (1 << j)][j]));
  }
  fill(dp + 1, dp + n + 1, 1e17);
  for (int i = 1; i <= n; i++) {
    dp[i] = min(dp[i - 1] + a[i], dp[i]);
    if (i >= c)
      dp[i] =
          min(dp[i - c] + sum[i] - sum[i - c] - getMin(i - c + 1, i), dp[i]);
  }
  cout << dp[n];
}
