#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
int n, c;
int v[100100];
long long dp2[100100];
long long dp[100100][22];
int d[100100];
void build() {
  d[0] = d[1] = 0;
  for (int i = 2; i <= n; i++) d[i] = d[i >> 1] + 1;
  for (int j = 1; j < 22; j++) {
    for (int i = 1; i + (1 << (j - 1)) <= n; i++) {
      dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
    }
  }
}
long long query(int i, int j) {
  int k = d[j - i];
  int x = min(dp[i][k], dp[j - (1 << k) + 1][k]);
  return x;
}
int main() {
  scanf("%d %d", &n, &c);
  if (c == 1) {
    printf("%d\n", 0);
    return 0;
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
    sum += v[i];
    dp[i][0] = v[i];
  }
  if (c > n) {
    cout << sum << endl;
    return 0;
  }
  build();
  for (int i = c; i <= n; i++) {
    dp2[i] = max(dp2[i - 1], dp2[i - c] + query(i - c + 1, i));
  }
  cout << sum - dp2[n] << endl;
  return 0;
}
