#include <bits/stdc++.h>
using namespace std;
#define int int64_t
void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    multiset<pair<int, int>> s;
    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += a[i];
        s.insert({-a[i], -i});
    }
    ans = sum + k;
    auto it = s.end();
    it--;
    for (int i = k; i < n; i++) {
        s.insert({-a[i], -i});
        if (a[i] >= -(*it).first) {
            sum += (*it).first;
            sum += a[i];
            it--;
            ans = max(ans, sum + i + 1);
        }
        else {
            ans = max(ans, sum + (*it).first + i + 1 + a[i]);
        }
    }
    cout << ans;
}
int32_t main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}
