#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
    int n, k;
    cin >> n >> k;
    vector <int> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    set <pair <int, int>> s;
    int summ = 0;
    for (int i = 0; i < k; ++i) {
        s.insert({arr[i], i});
        summ += arr[i];
    }
    int ans = summ + k;
    for (int i = k + 1; i < n; ++i) {
        ans = max(ans, summ - (*s.begin()).first + arr[i] + i + 1);
        s.insert({arr[i], i});
        s.erase(s.begin());
    }
    cout << ans << endl;
    return 0;
}
