#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define yes() cout << "YES\n"
#define no() cout << "NO\n"
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;

template<typename K>
using oset = tree<K, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int& i : a) cin >> i;

    int ans = 0;
    set<pair<int, int>> st;
    for (int i = 0; i < n; i++) {
        st.insert({-a[i], i});
    }

    int t = k - 1;
    while (t > 0) {
        t--;
        int idx = st.begin()->second;
        st.erase(st.begin());
        ans += a[idx] + 1;
        a[idx] = 0;
    }

    int prime = 0;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) continue;
        prime++;
        mx = max(mx, a[i] + prime);
    }

    cout << mx + ans << "\n";
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--) {
        solve();
    }
}