#include <bits/stdc++.h>
using namespace std;
template <int MAXN>
struct segtree {
  struct node_t {
    int x;
    node_t(int x = 1123123123) : x(x) {}
    node_t& operator+=(const node_t& other) {
      x = min(x, other.x);
      return *this;
    }
    node_t operator+(const node_t& other) const {
      node_t tmp = *this;
      tmp += other;
      return tmp;
    }
  };
  node_t a[2 * MAXN];
  void init() {
    for (int i = 1; i <= MAXN; i++) {
      a[i + MAXN - 1] = node_t();
    }
    for (int i = MAXN - 1; i > 0; i--) {
      a[i] = a[2 * i] + a[2 * i + 1];
    }
  }
  node_t get(int l, int r, int node = 1, int nl = 1, int nr = MAXN) {
    if (r < nl || nr < l) {
      return node_t();
    }
    if (l <= nl && nr <= r) {
      return a[node];
    }
    int nm = (nl + nr) >> 1;
    return get(l, r, 2 * node, nl, nm) + get(l, r, 2 * node + 1, nm + 1, nr);
  }
  void add(int pos, node_t val) {
    pos += MAXN - 1;
    a[pos] += val;
    while (pos > 1) {
      pos >>= 1;
      a[pos] = a[2 * pos] + a[2 * pos + 1];
    }
  }
  void set(int pos, node_t val) {
    pos += MAXN - 1;
    a[pos] = val;
    while (pos > 1) {
      pos >>= 1;
      a[pos] = a[2 * pos] + a[2 * pos + 1];
    }
  }
};
segtree<131072> drvo;
int n, c;
int a[100005];
long long dp[100005], z[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  cin >> n >> c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    z[i] = z[i - 1] + a[i];
    drvo.set(i, a[i]);
  }
  if (c == 1) {
    cout << "0\n";
    return 0;
  }
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i - 1] + a[i];
    if (i >= c) {
      dp[i] =
          min(dp[i], dp[i - c] + z[i] - z[i - c] - drvo.get(i - c + 1, i).x);
    }
  }
  cout << dp[n] << "\n";
}
