#include <bits/stdc++.h>

using namespace std;

#define int int64_t
#define fi first
#define ase second

const int N = 5e5 + 12;
int a[N], A[N];

int32_t main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        A[i] = a[i];
    }
    int ans = 0;
    n--;
    k--;
    sort(a, a + n, greater<>());
    multiset <int> ban;
    for(int i = 0; i < k; ++i) {
        ans += a[i] + 1;
        ban.insert(a[i]);
    }
    n++;
    vector <int> b;
    for(int i = 0; i < n; ++i) {
        if(ban.find(A[i]) != ban.end()) {
            ban.erase(ban.find(A[i]));
        } else {
            b.push_back(A[i]);
        }
    }
    int mx = 0, i = 1;
    for(auto to : b) {
        mx = max(mx, to + i);
        i++;
    }
    cout << ans + mx;
    return 0;
}
