#include <bits/stdc++.h>

#define ll long long

using namespace std;

void fast_in_out() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

ll n, i, a[500010], k, cnt = 0, cnt1, cnt2, ans = 0, used[500010], j,mx=0;
multiset<ll> s;
map<ll, ll> m;

int main() {
    fast_in_out();
    cin >> n >> k;
    for(i=0;i<n;i++)cin >> a[i],s.insert(a[i]);
    while(s.size()>k-1){
        s.erase(s.begin());
    }
    for(i=0;i<n;i++){
        if(s.find(a[i])!=s.end()){
            ans+=a[i]+1;
            s.erase(s.find(a[i]));
        }else{
            cnt++;
            mx=max(mx,a[i]+cnt);
        }
    }
    cout << ans+mx;
    return 0;
}
