#include "bits/stdc++.h"

using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rnd(time(0));
int n, k;
set<pair<int, int>> v;
ll ans = 0;

vector<int> v4;
ll ans2 = 0;

void rec(int ind, vector<vector<int>> v1) {
    if (ind == n) {
        ll ans1 = 0;
        for (int i = 0; i < k; i++) {
            int n1 = v1[i].size();
            if (n1 == 0)return;
            int ma = 0;
            for (int j = 0; j < n1; j++) {
                ma = max(ma, v1[i][j] + j + 1);
            }
            ans1 += ma;
        }
//        if (ans1 > ans2){
//            cout << ans1 << '\n';
//            for (auto i : v1){
//                for (auto j : i)cout << j << ' ';
//                cout << '\n';
//            }
//            cout << '\n';
//        }
        ans2 = max(ans2, ans1);
        return;
    }
    for (int i = 0; i < k; i++) {
        v1[i].push_back(v4[ind]);
        rec(ind + 1, v1);
        v1[i].pop_back();
    }
}

void solve() {
    cin >> n >> k;

    vector<int> v1(n), v6(n);
    v4.resize(n);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v1[i] = x;
        v6[i] = x;
        v4[i] = x;
        v.insert({x, i});
    }


//    return;
    int cnt = n - k;
    for (int i = 0; i < cnt; i++) {
        auto [x, in] = *v.begin();
        v.erase(v.begin());
        int x2 = -1, in2 = -1;
        for (auto [x1, in1]: v) {
            if (in1 > in) {
                if (x1 > x2) {
                    in2 = in1;
                    x2 = x1;
                } else if (x1 == x2) {
                    in2 = max(in2, in1);
                }
            }
        }

        if (in2 != -1) {
            v.erase(v.find({x2, in2}));
            v.insert({x2 + 1 + (x - v6[in]), in2});
        }
//        for (auto [x, in]: v) {
//            cout << x << ' ' << in << '\n';
//        }
//        cout << '\n';
    }
    for (auto i: v)ans += i.ff;
    cout << ans + k << ' ';
//    vector<vector<int>> v5(k);
//    rec(0, v5);
//    cout << ans2;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}