#include <string>
#include <bitset>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <iomanip>
#include <iostream>
#include <algorithm>

using namespace std;
using ll = long long;
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

void fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cout << setprecision(8) << fixed;
}

ll mod = 1e9 + 7;
ll binpow(ll a, ll n) {
    ll res = 1;
    for (int i = 0; (1ll << i) <= n; ++i, a = a * a % mod) {
        if ((n >> i) & 1) res = res * a % mod;
    }
    return res;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<pair<int, int>> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = make_pair(a[i], i);
    }
    sort(all(b), [](pair<int, int> f, pair<int, int> s) {
        if (f.first == s.first) return f.second > s.second;
        return f.first > s.first;
    });
    ll ans = 0;
    for (int i = 0; i < k - 1; ++i) {
        ans += b[i].first;
        a[b[i].second] = -1;
    }
    ll mx = 0;
    ll cur = 0;
    for (int i = 0; i < n; ++i) {
        cur++;
        if (a[i] == -1) {
            ans += cur;
            cur = 0;
            mx = 0;
            continue;
        }
        mx = max(mx, a[i] + cur);
    }
    ans += mx;
    cout << ans;
}
int main() {
    fast();
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}