#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ld = long double;
/*ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);*/
mt19937 rng;
ll randInt(ll l = 1, ll r = (ll)1e18) {
    return uniform_int_distribution<ll>(l, r)(rng);
}



int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (auto & i : a) cin >> i;
    ll s = 0, ma = 0;
    multiset<ll> q;
    for (int i = 0; i < k; i++) {
        s += a[i];
        q.insert(a[i]);
    }
    ma = s + k;
    for (int i = k; i < n; i++) {
        ll mi = *q.begin();
        q.erase(q.begin());
        q.insert(a[i]);
        s = s + a[i] - mi;
        ma = max(ma, s + i + 1);
    }
    cout << ma;

    return 0;
}
