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

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

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test = 1;
    for (int i = 0; i < test; i++) {
        solve();
    }
}
