#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    vector <pair <int, int>> b;
    for (int i = 0; i < n; ++i){
        cin >> a[i];
        b.push_back({a[i], i});
    }
    sort(b.begin(), b.end());
    vector <int> ind, all(n);
    int mxind = 0, sm = 0;
    for (int i = n - k;  i< n; ++i){
        ind.push_back(b[i].second);
        sm += b[i].first;
        all[b[i].second] = 1;
        mxind = max(mxind, b[i].second);
    }
    int cur = a[ind[0]];
    for (int i = mxind + 1; i < n; ++i){
        if (a[i] + i - mxind > cur){
            sm -= cur;
            cur = a[i] + i - mxind;
            sm += cur;
        }
    }
    cout << sm + mxind + 1;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--){
        solve();
    }
}



