#include "bits/stdc++.h"

using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rnd(time(0));

const int maxn = 5e5 + 5;
int a[maxn];
pair<int, int> tree[maxn * 4];


void build(int i, int l, int r) {
    if (r - l == 1) {
        tree[i] = {a[l], l};
        return;
    }
    int m = (l + r) / 2;
    build(i * 2 + 1, l, m);
    build(i * 2 + 2, m, r);
    if (tree[i * 2 + 1].ff > tree[i * 2 + 2].ff) {
        tree[i] = tree[i * 2 + 1];
    } else if (tree[i * 2 + 1].ff < tree[i * 2 + 2].ff) {
        tree[i] = tree[i * 2 + 2];
    } else {
        tree[i] = {tree[i * 2 + 1].ff, max(tree[i * 2 + 1].ss, tree[i * 2 + 2].ss)};
    }
}

pair<int, int> get(int i, int l, int r, int ql, int qr) {
    if (ql <= l && qr >= r) {
        return tree[i];
    }
    if (ql >= r || qr <= l)return {-1, 0};

    int m = (l + r) / 2;
    pair<int, int> p1 = get(i * 2 + 1, l, m, ql, qr), p2 = get(i * 2 + 2, m, r, ql, qr);
    if (p1.ff > p2.ff) {
        return p1;
    } else if (p1.ff < p2.ff) {
        return p2;
    } else {
        return {p1.ff, max(p1.ss, p2.ss)};
    }
}

void updt(int i, int l, int r, int qi, int val) {
    if (r - l == 1) {
        tree[i] = {val, l};
        return;
    }

    int m = (l + r) / 2;
    if (qi < m)updt(i * 2 + 1, l, m, qi, val);
    else updt(i * 2 + 2, m, r, qi, val);
    if (tree[i * 2 + 1].ff > tree[i * 2 + 2].ff) {
        tree[i] = tree[i * 2 + 1];
    } else if (tree[i * 2 + 1].ff < tree[i * 2 + 2].ff) {
        tree[i] = tree[i * 2 + 2];
    } else {
        tree[i] = {tree[i * 2 + 1].ff, max(tree[i * 2 + 1].ss, tree[i * 2 + 2].ss)};
    }
}

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;
        a[i] = x;
        v1[i] = x;
        v6[i] = x;
        v4[i] = x;
        v.insert({x, i});
    }
    build(0, 0, n);
//    updt(0, 0, n, 1, 2);
//    cout << get(0, 0, n, 1, 2).ff;
//    return;
//    return;
    int cnt = n - k;
    for (int i = 0; i < cnt; i++) {
        auto [x, in] = *v.begin();
        v.erase(v.begin());
        pair<int, int> p = get(0, 0, n, in + 1, n);
        int x2 = p.first, in2 = p.second;
//        cout << x2 << ' ' << in2 << '\n';

        if (x2 >= x) {
            v.erase(v.find({x2, in2}));
            updt(0, 0, n, in2, x2 + 1 + (x - v6[in]));
            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();
    }
}