#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define all(a) a.begin(), a.end()

int main() {
    ll n, k;
    cin >> n >> k;
    vector<pii> a(n);
    vector<ll> a0(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i].first;
        a0[i] = a[i].first;
        a[i].second = i;
    }
    sort(all(a), [](pii &p, pii &q) {
         if (p.first == q.first)
            return p.second > q.second;
         return p.first < q.first;
    });
    vector<bool> f(n);
    f[n - 1] == true;
    ll ans = 0;
    for (ll i = n - 1; i > n - k; --i) {
        f[a[i].second] = true;
        //cout << a[i].first + 1 << "\n";
        ans += a[i].first + 1;
    }
    ll mx = 0;
    ll cnt = 1;
    for (ll i = 0; i < n; ++i) {
        if (f[i]) continue;
        mx = max(mx, a0[i] + cnt);
        ++cnt;
    }
    //cout << mx << "\n";
    ans += mx;
    cout << ans;
}
