#include <bits/stdc++.h>

using namespace std;

void solve();

//#pragma GCC optimize("O3","Ofast","fastmath","unroll-loops")
//#pragma GCC target("avx2","sse4.2","bmi","lzcnt","popcnt")
int main() {
#ifdef LOCAL
    freopen("input.txt","r",stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#define int long long
#define endl '\n'
const int N=3e5+10,INF=2e18,MOD=1e9+7;

void solve(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    vector<pair<int,int>> b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]={a[i]+i,i};
    }
    sort(b.rbegin(),b.rend());
    int ans=0;
    int mxv=0;
    for(int i=0;i<k;i++){
        ans+=a[b[i].second];
        mxv=max(mxv,b[i].second);
    }
    mxv++;
    ans+=mxv;
    cout<<ans<<endl;
}