#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>


#define out(x) std::cout << x << ' ';
#define oute(x) std::cout << x << '\n';
#define enter std::cout << '\n';
#define debout(x) std::cout << #x << x << '\n';
#define debvout(x) std::cout << #x << " : "; for (auto i: x) std::cout << x << ' '; std::cout << '\n';
#define all(x) x.begin(), x.end()
using ll = long long;

void s1nmeee() {
    ll n, k;
    std::cin >> n >> k;
    std::vector<ll> a(n);
    std::vector<std::pair<ll, ll>> b;
    for (ll i = 0; i < n; i++) {
        std::cin >> a[i];
        b.emplace_back(a[i], i);
    }
    std::sort(all(b));
    std::vector<bool> used(n);
    ll ans = 0;
    for (ll i = n - 1; i > n - 1 - (k - 1); i--) ans += b[i].first + 1, used[b[i].second] = true;
    ll cnt = 0, mx = 0;
    for (ll i = 0; i < n; i++) {
        if (!used[i]) {
            cnt++;
            mx = std::max(mx, a[i] + cnt);
        }
    }
    out(ans + mx)
}

signed main() {
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false);
    ll TT = 1;
    // std::cin >> TT;
    while (TT--) {
        s1nmeee();
        std::cout << '\n';
    }
}