#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int LOGN = 18;
int n;
namespace ST {
int minv[LOGN][MAXN];
inline void init() {
  for (int k = 1; (1 << k) <= n; ++k)
    for (int i = 1, en = n - (1 << k) + 1; i <= en; ++i)
      minv[k][i] = min(minv[k - 1][i], minv[k - 1][i + (1 << (k - 1))]);
}
inline int query(int l, int r) {
  int len = r - l + 1, k = 0;
  while (1 << (k + 1) <= len) ++k;
  return min(minv[k][l], minv[k][r - (1 << k) + 1]);
}
}  // namespace ST
int len, a[MAXN];
long long c[MAXN], f[MAXN];
int main() {
  scanf("%d%d", &n, &len);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    f[i] = c[i] = c[i - 1] + a[i];
    ST::minv[0][i] = a[i];
  }
  ST::init();
  for (int i = len; i <= n; ++i)
    f[i] = min(f[i - 1] + a[i],
               f[i - len] + c[i] - c[i - len] - ST::query(i - len + 1, i));
  printf("%I64d\n", f[n]);
  return 0;
}
