#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INF = 1e9 + 7;
const int N = 120000;
int arr[N];
ll dp[N];
struct Node {
  int l, r;
  ll val;
} node[N << 2], pode[N << 2];
void build(int n, int l, int r) {
  node[n].l = l;
  node[n].r = r;
  if (l == r) {
    node[n].val = arr[l];
    return;
  }
  int mid = (l + r) >> 1;
  build(n << 1, l, mid);
  build(n << 1 | 1, mid + 1, r);
  node[n].val = min(node[n << 1].val, node[n << 1 | 1].val);
}
void puild(int n, int l, int r) {
  pode[n].l = l;
  pode[n].r = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  puild(n << 1, l, mid);
  puild(n << 1 | 1, mid + 1, r);
}
void update(int n, int x, ll d) {
  if (pode[n].l == pode[n].r && pode[n].l == x) {
    pode[n].val = d;
    return;
  }
  int mid = (pode[n].l + pode[n].r) >> 1;
  if (x <= mid)
    update(n << 1, x, d);
  else
    update(n << 1 | 1, x, d);
  pode[n].val = max(pode[n << 1].val, pode[n << 1 | 1].val);
  return;
}
ll query(int n, int l, int r) {
  if (node[n].l >= l && node[n].r <= r) return node[n].val;
  int mid = (node[n].l + node[n].r) >> 1;
  if (r <= mid)
    return query(n << 1, l, r);
  else if (l >= mid + 1)
    return query(n << 1 | 1, l, r);
  else
    return min(query(n << 1, l, mid), query(n << 1 | 1, mid, r));
}
int puery(int n, int l, int r) {
  if (pode[n].l >= l && pode[n].r <= r) return pode[n].val;
  int mid = (pode[n].l + pode[n].r) >> 1;
  if (r <= mid)
    return puery(n << 1, l, r);
  else if (l >= mid + 1)
    return puery(n << 1 | 1, l, r);
  else
    return max(puery(n << 1, l, mid), puery(n << 1 | 1, mid, r));
}
int main() {
  int n, c;
  scanf("%d%d", &n, &c);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    sum += arr[i];
  }
  if (c == 1)
    return 0 * printf("0\n");
  else if (c > n)
    return 0 * printf("%I64d\n", sum);
  build(1, 1, n);
  puild(1, 1, n);
  for (int i = c; i <= n; i++) {
    dp[i] = dp[i - c] + query(1, i - c + 1, i);
    dp[i] = max(dp[i], dp[i - 1]);
  }
  printf("%I64d\n", sum - dp[n]);
  return 0;
}
