#include <bits/stdc++.h>
#include <ext//pb_ds//assoc_container.hpp>

using namespace std;
using ll = long long;
using namespace __gnu_pbds;
using ordered_set = tree<ll, null_type, less_equal < ll>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ll n, k;
    cin >> n >> k;
    multiset <pair<ll, int>> s;
    pair<ll, int> m = {0, 0};
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        s.insert({x, i});
        m = max(m, {x + i, i});
    }
    auto i = s.end();
    multiset<pair<ll, int> > sol;
    ll ans = 0;
    int ml = 0;
    for (int j = 0; j < k - 1; j++) {
        --i;
        sol.insert(*i);
        ans += i->first;
        ml = max(ml, i->second);
    }
    if (sol.count({m.first-m.second, m.second}) == 0) {
        cout << ans + m.first + 1;
    } else {
        --i;
        ml = max(ml, i->second);
        ans += i->first + 1;
        cout << ans + ml;
    }
    return 0;
}
