#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
#pragma GCC target("avx,avx2,bmi,bmi2")

using namespace std;

#define all(x) (x).begin(),x.end()

#ifdef DBG
#define debug(x) cout << #x << " = " << (x) << endl
#else
#define debug(x) 
#endif

using ll = long long;

const int INF = 1e9;

mt19937 rnd(42);


inline void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    multiset<int> mx;
    for (int& i : v) cin >> i;

    ll ans = 0;
    ll sm = 0;
    for (int i = 0; i < n; ++i) {
        ll a = i + 1 + v[i] + sm;
        ans = max(a, ans);

        sm += v[i];
        mx.insert(v[i]);
        if (mx.size() >= m) {
            sm -= *mx.begin();
            mx.erase(mx.begin());
        }
    }

    cout << ans << endl;
} 


int main() {
    int t = 1;
    #ifdef DBG
    cin >> t;
    #endif
    for (int i = 0; i < t; ++i) {
        solve();
        #ifdef DBG
        cout << '\n';
        #endif
    }
}