#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back

using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    map <int, int> cnt;
    vector <int> v;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
        v.pb(a[i]);
    }
    int ans = n;
    int res = 0;
    map <int, int> us;
    map <int, int> usd;
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for(int i = 0; i < k; i++) {
        ans += v[i];
        us[v[i]]++;
        usd[v[i]]++;
    }
    if(us[a[n]]) {
        cout << ans;
        return 0;
    }
    else {
        ans -= (n - (k - 1));
        ans -= v[k - 1];
        us[v[k - 1]]--;
        usd[v[k - 1]]--;
    }
    map <int, bool> us2;
    for(int i = n; i >= 1; i--) {
        if(us[a[i]] > 0) {
            us[a[i]]--;
            us2[i] = 1;
        }
    }
    int mn = 0;
    for(int i = 1; i <= n; i++) {
        if(us2[i]) {
            mn++;
            if(usd[a[i]] != cnt[a[i]]) {
                int add = i - mn;
                res = max(res, a[i] + add);
            }
        }
        else {
            int add = i - mn;
            res = max(res, a[i] + add);
        }
    }
    cout << ans + res;
}
