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


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

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int ttt = 1;
    //cin >> ttt;
    while (ttt--) {
        solve();
    }
}
