#include <bits/stdc++.h>

using namespace std;

#ifndef lisie_bimbi
#define endl '\n'
#endif

const int N = 1100;

random_device rd;

mt19937 rnd(rd());

using ll = long long;

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

signed main(){
#ifdef lisie_bimbi
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    cin.tie(nullptr)->sync_with_stdio(false);
#endif            
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}