#include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, x, y, z, l, r, mid, ans, mod = 1000000007, h, g, m;
long long a[100005], b[100005], d[100005], st[400005];
char ch;
string s;
vector<long long> v, u;
void build(int nd, int s, int e) {
  if (s == e)
    st[nd] = a[s];
  else {
    int mid = (s + e) >> 1;
    build(2 * nd, s, mid);
    build(2 * nd + 1, mid + 1, e);
    st[nd] = min(st[2 * nd], st[2 * nd + 1]);
  }
}
long long query(int nd, int s, int e, int l, int r) {
  if (r < s || e < l) return 1e10;
  if (l <= s && e <= r) return st[nd];
  int mid = (s + e) >> 1;
  long long p1 = query(2 * nd, s, mid, l, r);
  long long p2 = query(2 * nd + 1, mid + 1, e, l, r);
  return min(p1, p2);
}
long long dp(int i) {
  if (i > n) return 0;
  if (d[i] + 1) return d[i];
  d[i] = a[i] + dp(i + 1);
  if (i + k - 1 <= n)
    d[i] = min(d[i], b[i + k - 1] - b[i - 1] - query(1, 1, n, i, i + k - 1) +
                         dp(i + k));
  return d[i];
}
int main() {
  ios::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = b[i - 1] + a[i];
  }
  build(1, 1, n);
  memset(d, -1, sizeof d);
  ans = dp(1);
  cout << ans;
}
