#include <bits/stdc++.h>
#define fx first
#define sx0 second
#define pb push_back
typedef long long ll;
const int Max = 100006;
const int Inf = 2e9;
const int MOD = 666013;
using namespace std;
deque <ll> q;
void add_in (ll a) {
while (!q.empty() && q.back() > a) q.pop_back();
q.push_back(a);
}
void remove (ll a) {
if (q.front() == a) q.pop_front();
}
void solve () {
ll n, k;
cin >> n >> k;
ll a[n+6];
for (int i=1; i<=n; i++) cin >> a[i];
ll ans = 0;
for (int i=1; i<=n; i++) {
add_in(a[i]);
if (i - k > 0) remove(a[i-k]);
if (i >= k) ans += q.front();
}
cout << ans << "\n";
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}