#include <bits/stdc++.h>
using namespace std;
int v[100005];
int st[100005][22];
bool mark[100005];
long long dp[100005];
int n, k;
void build() {
  int i, j;
  for (j = 1; 1 << j <= n; j++) {
    for (i = 0; i + (1 << j) <= n; i++) {
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
    }
  }
}
int getMin(int l, int r) {
  int num = r - l + 1, k = 0;
  while (num >= 2) num /= 2, k++;
  return min(st[l][k], st[r - (1 << k) + 1][k]);
}
long long f(int i) {
  if (i >= n) return 0;
  if (mark[i]) return dp[i];
  mark[i] = 1;
  long long ret = getMin(i - k + 1, i) + f(i + k);
  ret = max(ret, f(i + 1));
  return dp[i] = ret;
}
int main() {
  scanf("%d %d", &n, &k);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &st[i][0]);
    sum += st[i][0];
  }
  build();
  printf("%lld\n", sum - f(k - 1));
  return 0;
}
