#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//using ll = int;
using ld = long double;
using ull = unsigned long long;
#define pb push_back
#define all(vec) vec.begin(), vec.end()
#define eb emplace_back
#ifdef LOCAL
#define deb(x) cout << #x << " = " << x << '\n'
#else
#define deb(x) 52
#endif
const ll inf = 1e9 + 11;
const long long INF = (long long)2e18 + 11;
const ll P = 73;
const ll MOD = 1e9 + 7;


void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<ll> p(n - 1);
    for (ll i = 0; i < n - 1; ++i) {
        p[i] = i;
    }
    sort(all(p), [&](ll i, ll j) {
        return a[i] > a[j] || (a[i] == a[j] && i > j);
    });
    vector<bool> good(n), used(n);
    ll ans = 0;
    for (ll i = 0; i < k - 1; ++i) {
        good[p[i]] = true;
    }
    for (ll i = 0; i < k - 1; ++i) {
        ll cnt = 0;
        for (ll j = p[i] - 1; j >= 0; --j) {
            if (!good[j] && !used[j]) {
                used[j] = true;
                ++cnt;
            }
        }
        ans += a[p[i]] + cnt + 1;
    }
    ll c = 0;
    for (ll i = 0; i < n; ++i) {
        if (!used[i] && !good[i]) {
            ++c;
        }
    }
    ans += a.back() + c;
    cout << ans;
}


int main() {
#ifdef LOCAL
    freopen("C:/work/untitled/input.txt", "r", stdin);
    freopen("C:/work/untitled/output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll cfmode = 0;
    ll tc = 1;
    if (cfmode) {
        cin >> tc;
    }
    while (tc--) {
        solve();
        if (tc) {
            cout << '\n';
        }
    }
}