#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
const int maxn = 100005, maxlog = 20;
int mx[maxlog][maxn], n, c, v[100005];
long long f[maxn], sum[maxn];
inline int get(int l, int r) {
  int k = log2(r - l + 1);
  return min(mx[k][l], mx[k][r - (1 << k) + 1]);
}
int main() {
  read(n);
  read(c);
  for (int i = 1; i <= n; i++) {
    read(v[i]);
    mx[0][i] = v[i];
    sum[i] = sum[i - 1] + v[i];
  }
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      mx[j][i] = min(mx[j - 1][i], mx[j - 1][i + (1 << (j - 1))]);
  for (int i = 1; i < c; i++) f[i] = f[i - 1] + v[i];
  for (int i = c; i <= n; i++)
    f[i] = min(f[i - 1] + v[i],
               f[i - c] + sum[i] - sum[i - c] - get(i - c + 1, i));
  printf("%lld\n", f[n]);
}
