#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max(), MAX = 1e5,
                MOD = 1e9 + 7;
vector<long long> sp;
int n, c;
vector<long long> mem;
long long f(int i = 0) {
  if (i + c > n) return 0;
  if (mem[i] == -1) {
    mem[i] = max(mem[i], f(i + 1));
    mem[i] = max(mem[i], sp[i] + f(i + c));
  }
  return mem[i];
}
int main() {
  cin >> n >> c;
  vector<long long> v(n);
  mem.assign(n, -1);
  for (int i = 0; i < v.size(); i++) cin >> v[i];
  map<long long, int> m;
  for (int i = 0; i < min(c, n); i++) m[v[i]]++;
  for (int i = 0; i <= n - c; i++) {
    sp.push_back(m.begin()->first);
    auto it = m.find(v[i]);
    it->second--;
    if (it->second == 0) m.erase(it);
    if (i + c < n) m[v[i + c]]++;
  }
  cout << accumulate(v.begin(), v.end(), 0LL) - f() << endl;
}
