#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll &i : a) cin >> i;
    vector<pair<ll, ll>> s;
    for (ll i = 0; i < n; i++) {
        s.emplace_back(a[i], i);
    }
    sort(s.rbegin(), s.rend());
    vector<ll> b;
    for (ll i = 0; i < k - 1; i++) {
        b.push_back(s[i].second);
    }
    sort(b.begin(), b.end());
    ll prev = -1, ans = 0;
    for (ll i : b) {
        //cout << i << ' ' << prev << '\n';
        ans += a[i] + (i - prev);
        prev = i;
    }
    if (prev != n - 1) ans += a.back() + (n - 1 - prev);
    else ans += a[0];
    cout << ans << '\n';
}
