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

int main(){
    long long n,k;
    cin >> n >> k;
    vector<long long> a(n);
    multiset<long long> s;
    for(long long i = 0;i < n;i++){
        cin >> a[i];
        s.insert(a[i] + i);
    }
    multiset<long long> s1;
    for(long long i = 0;i < k;i++){
        s1.insert(*s.rbegin());
        s.erase(s.find(*s.rbegin()));
    }
    long long ind = 1;
    long long ans = 0;
    for(long long i = 0;i < n;i++){
        if(s1.count(a[i] + i)){
            ans += a[i] + ind;
            s1.erase(s1.find(a[i] + i));
            ind = 1;
        }else{
            ind++;
        }

    }
    cout << ans;

}
