#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
int n, c, a[MAXN], f[MAXN], Min[MAXN][30];
long long dp[MAXN][2];
void rmq1() {
  for (int i = 1; i <= n; ++i) Min[i][0] = a[i];
  for (int j = 1; 1 << j <= n; ++j) {
    for (int i = 1; i + (1 << j) - 1 <= n; ++i)
      Min[i][j] = min(Min[i][j - 1], Min[i + (1 << (j - 1))][j - 1]);
  }
}
int rmq2(int lef, int rig) {
  int k = 0;
  while (1 << (k + 1) <= rig - lef + 1) ++k;
  return min(Min[lef][k], Min[rig - (1 << k) + 1][k]);
}
int main() {
  memset(f, INF, sizeof(f));
  memset(dp, 0, sizeof(dp));
  scanf("%d%d", &n, &c);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  if (c == 1) {
    puts("0");
    return 0;
  }
  rmq1();
  for (int i = c; i <= n; ++i) {
    f[i] = rmq2(i - c + 1, i);
  }
  for (int i = c; i <= n; ++i) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = max(dp[i - c][0], dp[i - c][1]) + f[i];
  }
  printf("%lld\n", sum - max(dp[n][0], dp[n][1]));
  return 0;
}
