#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


int main(int, char**) {
    cout << setprecision(15) << fixed;
#ifdef DEBUGMB
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif

    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    multiset<ll> s;
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        s.insert(a[i]);
    }


    ll mx = 0;
    ll cnt = 0;
    vector<bool> used(n, false);
    ll ans = n;
    for (ll i = n - 1; i >= 0; --i) {
        if (used[i]) continue;
        if (a[i] > mx && cnt < k - 1) {
            used[i] = true;
            s.erase(s.find(a[i]));
            mx = a[i];
            ans += mx;
            for (ll j = 0; j < i; ++j) {
                if (a[j] <= a[i]) {
                    used[j] = true;
                }
            }
            cnt++;
        } else if (a[i] > mx && cnt == k - 1) {
            ll cntfree = 0;
            ll res = 0;
            for (ll j = 0; j <= i; ++j) {
                if (!used[j]) {
                    cntfree++;
                    res = max(res, a[j] + cntfree);
                }
            }
            ans += res - cntfree;
        }
    }
    while (cnt < k) {
        ans += *(s.rbegin());
        s.erase(--s.end());
        cnt++;
    }
    cout << ans << endl;


    return 0;
}
