#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#define endl '\n'
#define int long long

using namespace std;

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<bool> used(n, false);
    int sum = 0;
    set<pair<int, int>> d;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        d.insert({a[i], i});
    }
    while (k > 1) {
        k--;
        auto it = --d.end();
        sum += 1 + (it -> first);
        used[(it -> second)] = true;
        d.erase(it);
    }
    int mx = 0;
    int ad = 1;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            mx = max(mx, a[i] + ad);
            ad++;
        }
    }
    cout << sum + mx << endl;
    return 0;
}
