#define _GLIBCXX_DEBUG

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>

#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

constexpr ll inf = 1e18;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll &e : a) cin >> e;
    ll res = 0;
    for (int i = 0; i < n; ++i) res = max(res, a[i] + i + 1);
    a.pop_back();
    sort(all(a), greater());
    for (int i = 0; i < k - 1; ++i) res += a[i];
    cout << res;
}

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