#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long n, c, tot, a[100050], Rmin[100050][30], dp[100050];
void init() {
  for (int i = 1; i <= n; i++) Rmin[i][0] = i;
  for (int j = 1; 1 << j <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      int mid = i + (1 << (j - 1));
      if (a[Rmin[mid][j - 1]] < a[Rmin[i][j - 1]])
        Rmin[i][j] = Rmin[mid][j - 1];
      else
        Rmin[i][j] = Rmin[i][j - 1];
    }
}
inline int query(int y) {
  int x = y - c + 1;
  int le = log(1.0 * c) / log(2.0);
  if (a[Rmin[x][le]] < a[Rmin[y - (1 << le) + 1][le]]) return a[Rmin[x][le]];
  return a[Rmin[y - (1 << le) + 1][le]];
}
int main(int argc, char const *argv[]) {
  scanf("%lld%lld", &n, &c);
  for (int i = 1; i <= n; i++) scanf("%lld", a + i);
  for (int i = 1; i <= n; i++) tot += a[i];
  init();
  dp[1] = 0;
  if (c == 1) dp[1] = a[1];
  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i - 1];
    if (i - c >= 0) dp[i] = max(dp[i], query(i) + dp[i - c]);
  }
  printf("%lld\n", tot - dp[n]);
  return 0;
}
