// #pragma GCC optimize("Ofast,fast-math,unroll-loops,no-stack-protector,inline")
#include <bits/stdc++.h>

using namespace std;

#define int long long

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    multiset<int> st;
    int sm = 0;
    int ans = 0;
    for (int i = 0; i < k - 1; i++) {
        st.insert(arr[i]);
        sm += arr[i];
    }
    for (int i = k - 1; i < n; i++) {
        ans = max(ans, sm + (k - 1) + arr[i] + (i + 1) - (k - 1));
        sm += arr[i];
        st.insert(arr[i]);
        int cur = *st.begin();
        sm -= cur;
        st.erase(st.begin());
    }
    cout << ans << endl;
}