#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
const ll INF = numeric_limits<ll>::max(), MOD = 998244353;
const int MAX = 1e5;
int n, c;
vii mv(MAX);
vll dp(MAX, -1);
ll f(int i = 0) {
  if (i + c > n) {
    return 0LL;
  }
  if (dp[i] == -1) {
    ll res = mv[i] + f(i + c);
    res = max(res, f(i + 1));
    dp[i] = res;
  }
  return dp[i];
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> n >> c;
  vii v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  multiset<int> m;
  for (int i = n - 1; i >= 0; i--) {
    m.insert(v[i]);
    if (m.size() > c) {
      m.erase(m.find(v[i + c]));
    }
    mv[i] = *m.begin();
  }
  f();
  cout << accumulate(v.begin(), v.end(), 0LL) - f() << '\n';
}
