#include <bits/stdc++.h>
using namespace std;
void build(int ss, int se, int si);
long long query(int ss, int se, int si, int qs, int qe);
set<pair<long long, int> > s;
set<pair<long long, int> >::iterator it, last;
long long A[100001], st[400005], dp[100001];
int main(void) {
  int i, n, c;
  long long sum, ans = 0, min_i;
  cin >> n >> c;
  if (c == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    cin >> A[i];
    ans = ans + A[i];
  }
  build(0, n - 1, 0);
  for (i = c - 1; i < n; i++)
    dp[i] = max(dp[i - 1], ((i - c >= 0) ? dp[i - c] : 0) +
                               query(0, n - 1, 0, i - c + 1, i));
  cout << ans - dp[n - 1] << endl;
}
void build(int ss, int se, int si) {
  if (ss == se) {
    st[si] = A[ss];
    return;
  }
  int mid = (ss + se) / 2;
  build(ss, mid, 2 * si + 1);
  build(mid + 1, se, 2 * si + 2);
  st[si] = min(st[2 * si + 1], st[2 * si + 2]);
}
long long query(int ss, int se, int si, int qs, int qe) {
  if (ss >= qs && se <= qe) return st[si];
  if (ss > qe || se < qs) return INT_MAX;
  int mid = (ss + se) / 2;
  return min(query(ss, mid, 2 * si + 1, qs, qe),
             query(mid + 1, se, 2 * si + 2, qs, qe));
}
