#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const long long mod = 998244353;
int n, k, a[100010];
long long dp[100010], sum[100010];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    dp[i] = sum[i] = sum[i - 1] + a[i];
  }
  multiset<int> s;
  for (int i = 1; i <= n; ++i) {
    s.insert(a[i]);
    if (s.size() < k) continue;
    dp[i] = min(dp[i - 1] + a[i], dp[i - k] + sum[i] - sum[i - k] - *s.begin());
    s.erase(s.find(a[i - k + 1]));
  }
  cout << dp[n];
}
