#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238463;
const long long int dx4[4] = {0, 1, 0, -1};
const long long int dy4[4] = {-1, 0, 1, 0};
const long long int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const long long int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vector<string> vec_splitter(string s) {
  for (char& c : s) c = c == ',' ? ' ' : c;
  stringstream ss;
  ss << s;
  vector<string> res;
  for (string z; ss >> z; res.push_back(z))
    ;
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) long long int idx) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, long long int idx, Head H, Tail... T) {
  if (idx > 0) cerr << ", ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, T...);
}
const long long int N = 1e5 + 5;
long long int n, c;
vector<long long int> a(N), pref(N), dp(N), tree(4 * N);
void build(long long int id, long long int tl, long long int tr) {
  if (tl > tr) return;
  if (tl == tr) {
    tree[id] = a[tl];
    return;
  }
  long long int tm = (tl + tr) / 2;
  build(id * 2, tl, tm);
  build(id * 2 + 1, tm + 1, tr);
  tree[id] = min(tree[id * 2], tree[id * 2 + 1]);
}
long long int query(long long int id, long long int tl, long long int tr,
                    long long int l, long long int r) {
  if (tl > tr or r < tl or l > tr) {
    return 1e18;
  }
  if (l <= tl and tr <= r) {
    return tree[id];
  }
  long long int tm = (tl + tr) / 2;
  long long int left = query(id * 2, tl, tm, l, r);
  long long int right = query(id * 2 + 1, tm + 1, tr, l, r);
  return min(left, right);
}
long long int get_sum(long long int l, long long int r) {
  return pref[r] - pref[l - 1];
}
long long int get(long long int id) {
  if (id > n) return 0;
  auto& res = dp[id];
  if (res != -1) return res;
  if (id + c - 1 > n) {
    res = get_sum(id, n);
  } else {
    res = min(
        a[id] + get(id + 1),
        get_sum(id, id + c - 1) - query(1, 1, n, id, id + c - 1) + get(id + c));
  }
  return res;
}
void solve() {
  cin >> n >> c;
  fill(dp.begin(), dp.end(), -1);
  for (long long int i = 1; i <= n; ++i) {
    cin >> a[i];
    pref[i] = a[i] + pref[i - 1];
  }
  build(1, 1, n);
  cout << get(1) << '\n';
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long int T = 1;
  for (long long int i = 1; i <= T; ++i) {
    solve();
  }
  return 0;
}
