#include <bits/stdc++.h>
using namespace std;
mt19937_64 rng((long long)new char);
const double eps = 1e-8;
const int maxn = 200010;
const long double INF = 1e15;
const int mod = 1e9 + 7;
long long n, c;
long long dp[maxn], a[maxn];
int mi[maxn];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> c;
  for (int t = (1); t < (n + 1); ++t) cin >> a[t];
  dp[0] = 0;
  deque<pair<int, int>> q;
  if (c > n) {
    long long sum = 0;
    for (int t = (1); t < (n + 1); ++t) sum += a[t];
    cout << sum;
    return 0;
  }
  for (int t = (1); t < (c + 1); ++t) {
    while (!q.empty() && q.back().second >= a[t]) q.pop_back();
    q.push_back({t, a[t]});
  }
  mi[c] = q.front().second;
  for (int t = (c + 1); t < (n + 1); ++t) {
    while (!q.empty() && q.front().first < t - c + 1) q.pop_front();
    while (!q.empty() && q.back().second >= a[t]) q.pop_back();
    q.push_back({t, a[t]});
    mi[t] = q.front().second;
  }
  for (int t = (1); t < (n + 1); ++t) {
    dp[t] = dp[t - 1] + (c == 1 ? a[t] : 0);
    if (t >= c) {
      dp[t] = max(dp[t], dp[t - c] + mi[t]);
    }
  }
  long long sum = 0;
  for (int t = (1); t < (n + 1); ++t) sum += a[t];
  cout << sum - dp[n];
}
