#include<iostream>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<random>
#include<chrono>
#include<algorithm>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define int long long

signed main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    cout.precision(20);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    vector<pair<int, int>> all;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        all.push_back({v[i] + i + 1, i});
    }
    sort(all.rbegin(), all.rend());
    int ans = 0;
    vector<int> pos;
    for (int i = 0; i < k; i++) {
        ans += all[i].first;
        pos.push_back(all[i].second);
    }
    pos.push_back(-1);
    sort(pos.begin(), pos.end());
    // for (auto u : pos) {
    //     cout << u << ' ';
    // }
    // cout << '\n';
    for (int i = 1; i <= k; i++) {
        ans -= (pos[i] + 1 - (pos[i] - pos[i - 1]));
    }
    cout << ans << '\n';
}