#include<bits/stdc++.h>
#define int long long
using namespace std;

void solve() {
    int n, k, s = 0, ans = 0;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    if (k == 1) {
        for (int i = 0; i < n; i++) {
            ans = max(ans, a[i] + i + 1);
        }
        cout << ans;
        return;
    }
    multiset<int> b;
    for (int i = 0; i < k - 1; i++) {
        b.insert(a[i]);
        s += a[i];
    }
    for (int i = k - 1; i < n; i++) {
        ans = max(ans, s + k + (i - k + 1) + a[i]);
        if (a[i] > *b.begin()) {
            s -= *b.begin();
            s += a[i];
            b.erase(b.find(*b.begin()));
            b.insert(a[i]);
        }
    }
    cout << ans;
}

int32_t main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    solve();
}
