#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<ll> a(n), order(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        order[i] = i;
    }
    sort(all(order), [&a, &k](ll i, ll j) {
         if (k == 2)
            return a[i] < a[j];
         return a[i] > a[j];
    });
    ll ans = 0;
    vector<bool> f(n);
    for (ll i = 0; i < k - 1; ++i) {
        ans += a[order[i]] + 1;
        f[order[i]] = true;
    }
    ll mx = 0;
    ll cnt = 1;
    for (ll i = 0; i < n; ++i) if (!f[i]) {
        mx = max(mx, a[i] + cnt);
        ++cnt;
    }
    ans += mx;
    cout << ans;
}
