#include <bits/stdc++.h>
using namespace std;
#define int long long


main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector < int > a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector < int > A = a;
    sort(begin(A), end(A));
    int sum = 0;
    for (int i = n - k; i < n; i++) sum += A[i];
    sum += k;
    int idx;
    for (int i = 0; i < n; i++) if (a[i] >= A[n - k]) idx = i;
    sum += idx - k + 1;
    int ans = sum;
    sum -= idx - k + 1;
    sum -= A[n - k];
    if (n != k) {
        for (int i = 0; i < n; i++)
            if (a[i] <= A[n - k - 1]) ans = max(ans, sum + a[i] + i - k + 1);
    }
    cout << ans;

}
