#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define int long long
#define ld long double

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    set<int> heap;
    int cursm = 0;
    int ans = 0;
    int val;
    for (int i = 0; i < k - 1; i++) {
        heap.insert(a[i]);
        cursm += a[i];
    }
    for (int i = k - 1; i < n; i++) {
        val = a[i] + i + 1 - (k - 1);
        val += cursm + k - 1;
        ans = max(ans, val);
        if (!heap.empty()) {
            int t = *heap.begin();
            if (t < a[i]) {
                heap.erase(heap.begin());
                cursm -= t;
                heap.insert(a[i]);
                cursm += a[i];
            }
        }
    }
    cout << ans << '\n';
}
signed main() {
    solve();
}
