#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int maxn = 1e5 + 5;
long long a[maxn];
long long dp[maxn];
long long mi[maxn];
multiset<int> sv;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, k, m, n;
  cin >> n >> m;
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  for (int i = 1; i <= m; ++i) sv.insert(a[i]);
  dp[m] = mi[m] = *sv.begin();
  if (n < m) {
    cout << sum << endl;
    return 0;
  }
  for (int i = m + 1; i <= n; ++i) {
    sv.insert(a[i]);
    sv.erase(sv.find(a[i - m]));
    mi[i] = *sv.begin();
  }
  for (int i = m + 1; i <= n; ++i) {
    dp[i] = max(dp[i - 1], dp[i - m] + mi[i]);
  }
  cout << sum - dp[n] << endl;
  return 0;
}
