#include <bits/stdc++.h>

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")

#define int long long

using ll = long long;
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    multiset<int> s;
    vector<int> b, a(n), used(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    b = a;
    sort(b.begin(), b.end());
    if (a.back() >= b[n - k]) {
        int ans = 0;
        for (int i = n - 1; i >= n - k; i--) {
            ans += b[i];
        }
        ans += n;
        cout << ans << "\n";
        return;
    }
    for (int i = n - 1; i > n - k; i--) {
        s.insert(b[i]);
    }
    for (int i = n - 1; i > -1; i--) {
        if (s.find(a[i]) != s.end()) {
            s.erase(s.find(a[i]));
            used[i] = 1;
        }
    }
    int cnt = 1, mx = 0;
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            mx = max(cnt + a[i], mx);
            cnt++;
        }
    }
    if (mx == cnt + a.back() - 1) {
        int ans = 0;
        for (int i = n - 1; i > n - k; i--) {
            ans += b[i];
        }
        ans += a.back();
        ans += n;
        cout << ans << "\n";
        return;
    }
    int ind = -1;
    for (int i = 0; i < n; i++) {
        if (used[i]) {
            ind = i;
        }
    }
    cnt = 0;
    for (int i = 0; i <= ind; i++) {
        cnt += (used[i] == 0);
    }
    int cur = 1;
    mx = 0;
    for (int i = ind + 1; i < n; i++) {
        if (!used[i]) {
            mx = max(cur + a[i], mx);
            cur++;
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += used[i] * a[i];
    }
    cout << sum + mx + cnt << "\n";
}

signed main() {
    int t = 1;
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    cin >> t;
#else
    ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
#endif
//    cin >> t;
    while (t--) {
        solve();
    }
}
