#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long mod = 1000000007;
const double e = 2.718281828459;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long gcd1(int a, int b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long pow_mod(long long a, long long b, long long c) {
  long long ans = 1;
  a = a % c;
  while (b > 0) {
    if (b % 2 == 1) ans = (ans * a) % c;
    b = b / 2;
    a = (a * a) % c;
  }
  return ans;
}
int pow_int(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ans * a;
    b = b / 2;
    a = a * a;
  }
  return ans;
}
long long pow_llong(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ans * a;
    b = b / 2;
    a = a * a;
  }
  return ans;
}
const int dx[9] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int dy[9] = {0, 1, 0, -1, -1, -1, 0, 1, 1};
int Scan() {
  int res = 0, flag = 0;
  char ch;
  if ((ch = getchar()) == '-') {
    flag = 1;
  } else if (ch >= '0' && ch <= '9') {
    res = ch - '0';
  }
  while ((ch = getchar()) >= '0' && ch <= '9') {
    res = res * 10 + (ch - '0');
  }
  return flag ? -res : res;
}
void Out(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) {
    Out(a / 10);
  }
  putchar(a % 10 + '0');
}
long long jc_mod(long long a, long long b, long long mod) {
  long long ans = 1;
  b = max(b, a - b);
  for (long long i = a; i > b; i--) {
    ans *= i;
    ans %= mod;
  }
  return ans;
}
double lg(double a) { return (log(a) / log(10.0)); }
int lowbit(int x) { return x & -x; }
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void lisan(int *x, int n) {
  int data[100010];
  for (int i = 1; i <= n; i++) data[i] = x[i];
  sort(data + 1, data + 1 + n);
  int o = unique(data + 1, data + 1 + n) - data - 1;
  for (int i = 1; i <= n; i++)
    x[i] = lower_bound(data + 1, data + 1 + o, x[i]) - data;
}
int calc(int M) { return 1; }
int sanfen(int L, int R) {
  int M, RM;
  while (L + 1 < R) {
    M = (L + R) / 2;
    RM = (M + R) / 2;
    if (calc(M) < calc(RM))
      R = RM;
    else
      L = M;
  }
  return L;
}
void qmain() {
  freopen("in.txt", "w", stdout);
  cout << 100000 << " " << 99999 << endl;
  for (int i = 1; i <= 99999; i++) {
    printf("1 %d\n", i + 1);
  }
}
long long dp[100100];
static const int maxm = (1e5 + 10) * 4;
long long tree[maxm], lazy[maxm], A[maxm], lft[maxm], rit[maxm];
int n, m;
void build(int num, int l, int r) {
  lft[num] = l;
  rit[num] = r;
  int mid = (l + r) >> 1;
  if (l == r) {
    tree[num] = A[l];
    return;
  }
  build(num << 1, l, mid);
  build(num << 1 | 1, mid + 1, r);
  tree[num] = min(tree[num << 1], tree[num << 1 | 1]);
}
void pushdown(int num) {
  if (lazy[num]) {
    int mid = (lft[num] + rit[num]) >> 1;
    tree[num << 1] += (mid - lft[num] + 1) * lazy[num];
    tree[num << 1 | 1] += (rit[num] - mid) * lazy[num];
    lazy[num << 1] += lazy[num];
    lazy[num << 1 | 1] += lazy[num];
    lazy[num] = 0;
  }
}
void update(int num, int l, int r, long long add) {
  if (lft[num] >= l && rit[num] <= r) {
    tree[num] += (rit[num] - lft[num] + 1) * add;
    lazy[num] += add;
    return;
  }
  if (lft[num] > r || rit[num] < l) return;
  pushdown(num);
  update(num << 1, l, r, add);
  update(num << 1 | 1, l, r, add);
  tree[num] = tree[num << 1] + tree[num << 1 | 1];
}
long long Query(int num, int l, int r) {
  if (lft[num] >= l && rit[num] <= r) return tree[num];
  if (lft[num] > r || rit[num] < l) return INF;
  long long ret = 0;
  ret = min(Query(num << 1, l, r), Query(num << 1 | 1, l, r));
  return ret;
}
int main() {
  int n, c;
  scanf("%d%d", &n, &c);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &A[i]);
  }
  build(1, 1, n);
  long long sum = 0;
  for (int i = 1; i <= c - 1; i++) {
    dp[i] = dp[i - 1] + A[i];
    sum += A[i];
  }
  for (int i = c; i <= n; i++) {
    long long q = Query(1, i - c + 1, i);
    sum += A[i];
    dp[i] = min(dp[i - 1] + A[i], dp[i - c] + sum - q);
    sum -= A[i - c + 1];
  }
  printf("%I64d\n", dp[n]);
  return 0;
}
