#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
constexpr char nl = '\n';

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vi a(n);
    vector<pii> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = {a[i] + i, i};
    }
    sort(b.begin(), b.end(), [](const pii &i, const pii &j) {
        return i.first > j.first || (i.first == j.first && i.second > j.second);
    });
    ll ans = 0;
    int mx = 0;
    for (int i = 0; i < k; ++i) {
        int j = b[i].second;
        ans += a[j];
        mx = max(mx, j);
    }
    cout << ans + mx + 1;
}
