#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c;
  cin >> n >> c;
  int count = n / c;
  int free = n % c;
  vector<long long int> arr(100001, -1);
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    sum = sum + arr[i];
  }
  vector<long long int> mini(100001, -1);
  map<long long int, long long int> counter;
  for (int i = 1; i <= c; i++) {
    if (c > n) break;
    counter[arr[i]]++;
  }
  map<long long int, long long int>::iterator it = counter.begin();
  if (c <= n) mini[c] = it->first;
  for (int i = c + 1; i <= n; i++) {
    counter[arr[i]]++;
    counter[arr[i - c]]--;
    it = counter.find(arr[i - c]);
    if (it->second == 0) counter.erase(it);
    it = counter.begin();
    mini[i] = it->first;
  }
  vector<vector<long long int> > dp(n + 1, vector<long long int>(2, -1));
  for (int i = 0; i < c; i++) {
    if (i > n) break;
    dp[i][0] = 0;
  }
  for (int i = c; i <= n; i++) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = max(dp[i - c][0] + mini[i], dp[i - c][1] + mini[i]);
  }
  cout << (sum - max(dp[n][0], dp[n][1])) << endl;
  return 0;
}
