#include <bits/stdc++.h>

#include <atcoder/segtree>

using namespace std;
using namespace atcoder;

using S = int64_t;

S op(S a, S b) { return min(a, b); }

S e() { return 1e18; }

int main() {
    int n, k;
    cin >> n >> k;
    vector<int64_t> a(n);
    for (auto &&x : a) {
        cin >> x;
    }

    segtree<S, op, e> seg(n + 1);
    seg.set(0, 0);
    for (int i = 0; i < n; i++) {
        int l = i < k ? 0 : i - k + 1;
        seg.set(i + 1, seg.prod(l, i + 1) + a.at(i));
    }

    cout << reduce(a.begin(), a.end()) - seg.prod(n - k + 1, n + 1) << endl;

    return 0;
}