#include <bits/stdc++.h>

using namespace std;

#define int long long

mt19937 rnd(14);

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &i: a) {
        cin >> i;
    }
    vector<bool> used(n);
    vector<int> cc(n);
    for (int k1 = 0; k1 < k; ++k1) {
        vector<int> c(n);
        c.back() = cc.back();
        for (int i = n - 2; i >= 0; --i) {
            c[i] = cc[i] + c[i + 1];
            c[i] = min(c[i], 1ll);
        }
        int cnt = 1;
        int mx = 0, mxpos = 0;
        for (int i = 0; i < n; ++i) {
            if (!used[i]) {
                if (mx < a[i] + cnt - c[i]) {
                    mx = a[i] + cnt - c[i];
                    mxpos = i;
                }
                ++cnt;
            }
        }
        cc[mxpos]++;
        used[mxpos] = true;
    }
    int ans = 0, cnt = 1;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            ++cnt;
        } else {
            ans += a[i] + cnt;
            cnt = 1;
        }
    }
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("inp.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}
