//#pragma GCC optimize("unroll-loops","Ofast")
//#pragma GCC target("sse","sse2","avx","avx2")
#include <bits/stdc++.h>

#define int long long
#define F first
#define S second
using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    multiset<pair<int, int>> ms;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ms.insert({a[i] + i, i});
    }
    int ans = 0;
    for (int i = 0; i < k - 1; ++i) {
        auto it = --ms.end();
        ans += it->F - it->S + 1;
        a[it->S] = -1;
        ms.erase(it);
    }
    int mx = 0;
    int add = 1;
    for (int i = 0; i < n; ++i) {
        if (a[i] == -1) {
            continue;
        }
        mx = max(mx, a[i] + add);
        add++;
    }
    cout << ans + mx;
    return 0;
}
//не забудь сохранять коды!!!