#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int minn[N];
long long sum[N];
int arr[N];
long long dp[N];
multiset<int> seet;
int main() {
  int n, c;
  scanf("%d", &n);
  scanf("%d", &c);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &arr[i]), sum[i] = sum[i - 1] + arr[i];
  for (int i = 1, j = 1; i <= n; ++i) {
    while (j <= n && (j - i) < c) {
      seet.insert(arr[j]);
      ++j;
    }
    minn[i] = *(seet.begin());
    seet.erase(seet.find(arr[i]));
  }
  for (int i = n; i >= 1; --i) {
    dp[i] = dp[i + 1] + arr[i];
    if ((i + c) <= (n + 1)) {
      dp[i] = min(dp[i], dp[i + c] + (sum[i + c - 1] - sum[i - 1]) - minn[i]);
    }
  }
  printf("%lld\n", dp[1]);
}
