#include <bits/stdc++.h>

using ll = long long;
using namespace std;
int mod = 1e9 + 7;
struct mod_int {
    int v = 0;
    mod_int(int nv = 0) {
        v = nv;
        if (v < 0 || v >= mod) {
            v = (v % mod + mod) % mod;
        }
    }
};
mod_int operator + (mod_int v1, mod_int v2) {
    return (v1.v + v2.v >= mod ? v1.v + v2.v - mod : v1.v + v2.v);
}
mod_int operator -(mod_int v1, mod_int v2) {
    return (v1.v - v2.v < 0 ? v1.v - v2.v + mod : v1.v - v2.v);
}
mod_int operator *(mod_int v1, mod_int v2) {
    return (1LL * v1.v * v2.v) % mod;
}
bool operator == (mod_int v1, mod_int v2) {
    return v1.v == v2.v;
}
bool operator < (mod_int v1, mod_int v2) {
    return v1.v < v2.v;
}

void solve() {
    ll n;
    cin >> n;
    ll k;
    cin >> k;
    vector <ll> val(n);
    for (ll i = 0; i < n; ++i) {
        cin >> val[i];
    }
    vector <pair <ll, ll>> now{};
    for (ll i = 0; i < n; ++i) {
        now.push_back({- val[i], i});
    }
    ll ans = 0;
    sort(now.begin(), now.end());
    reverse(now.begin(), now.end());
    for (ll i = 0; i < k - 1; ++i) {
        ans += - now.back().first + 1;
        now.pop_back();
    }
    sort(now.begin(), now.end(), [](pair <ll, ll> &v1, pair <ll, ll> &v2) {
        return v1.second < v2.second;
    });
    ll d = 0;
    for (ll i = 0; i < now.size(); ++i) {
        d = max(d, - now[i].first + i + 1);
    }
//    cout << d << '\n';
    ans += d;
    cout << ans << '\n';
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t = 1;
//    cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }
}
