#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <bitset>
#include <string>

//#pragma GCC optimize("unroll-loops,inline,O2,O3,Ofast")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,sse4,ssse3,abm,mmx,fma,popcnt,lzcnt")

using namespace std;

typedef long long ll;

ll INF = 1e18 + 9;

void solve() {

    ll n, m, ans = 0;
    cin >> n >> m;

    vector<ll> a(n);
    set<pair<ll, ll>> s;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s.insert({a[i], i});
    }

    for (int i = 0; i < m - 1; i++) {
        auto p = --s.end();
        ans += p->first;
        a[p->second] = -INF;
        s.erase(--s.end());
    }

    ll sm = 0;
    for (int i = 0; i < n; i++) {
        if (i + 1 + a[i] > sm) {
            sm = i + 1 + a[i];
        }
    }
    cout << ans + sm;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << "\n";
    }

    return 0;
}
