#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;
    }
    if (k == 2) {
        vector<ll> pref(n), suf(n);
        pref[0] = a[0] + 1;
        for (ll i = 1; i < n; ++i) {
            pref[i] = max(pref[i - 1], a[i] + i + 1);
        }
        suf[n - 1] = a[n - 1] + n;
        for (ll i = n - 2; i >= 0; --i) {
            suf[i] = max(suf[i + 1], a[i] + i + 1);
        }
        ll ans = 0;
        for (ll i = 0; i < n - 1; ++i) {
            ans = max(ans, pref[i] + suf[i + 1] - i - 1);
        }
        for (ll i = 1; i < n - 1; ++i) {
            ll x = max(pref[i - 1], suf[i + 1] - 1);
            ans = max(ans, x + a[i] + 1);
        }
        cout << ans;
        return 0;
    }
    sort(all(order), [&a](ll i, ll 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;
}
