#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

//#pragma GCC optimize("Ofast, unroll-loops, fast-math, no-stack-protector, inline")
//#pragma GCC target("avx, avx2")

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
//#define int long long

const ll INF = 2e9 + 228;
const ll mod = 1e9 + 7;
const ld eps = 1e-8;

random_device rd;
mt19937 rnd(rd() + 228 + 57 - 179);

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
    if (a.first == b.first) return a.second < b.second;
    return a.first > b.first;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<pair<ll, ll>> b(n);
    for (int i = 0; i < n; ++i) {
        b[i] = {a[i], i};
    }
    vector<int> used(n);
    sort(b.begin(), b.end(), cmp);
    ll ans = 0;
    for (int i = 0; i + 1 < k; ++i) {
        used[b[i].second] = 1;
        ans += b[i].first + 1;
    }
    ll mx = -INF;
    ll p = 1;
    for (int i = 0; i < n; ++i) {
        if (used[i]) continue;
        mx = max(mx, a[i] + p);
        ++p;
    }
    ans += mx;
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int tt = 1;
    //cin >> tt;
    while (tt--) solve();
    return 0;
}
