#include <bits/stdc++.h>
using namespace std;
int main() {
  multiset<long long> s;
  long long n, c;
  cin >> n >> c;
  long long sum = 0;
  long long a[n + 10];
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  if (n < c) {
    cout << sum;
    return 0;
  }
  for (int i = 1; i < c; ++i) s.insert(a[i]);
  long long r[n + 10];
  for (int i = c; i <= n; ++i) {
    s.insert(a[i]);
    for (auto v : s) {
      r[i] = v;
      break;
    }
    s.erase(s.find(a[i - c + 1]));
  }
  long long dp[n + 10];
  for (int i = 0; i < c; ++i) dp[i] = 0;
  for (int i = c; i <= n; ++i) dp[i] = max(dp[i - 1], dp[i - c] + r[i]);
  cout << sum - dp[n];
  return 0;
}
