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

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    vector<pair<int, int>> b(n);
    for (int i = 0; i < n; ++i) b[i] = {a[i], i};
    sort(b.rbegin(), b.rend());
    vector<int> luch, por(n);
    int skm1 = 0, sk = 0;
    for (int i = 0; i < n; ++i){
        por[b[i].second] = i;
        if (i >= k) luch.push_back(b[i].second);
        if (i < k) sk += b[i].first;
        if (i < k-1) skm1 += b[i].first;
    }
    int ans = 0; sort(luch.begin(), luch.end());
    for (int i = 0; i < n; ++i){
        int res = (por[i] >= k-1 ? skm1 : sk - a[i]);
        res += a[i];
        res += (upper_bound(luch.begin(), luch.end(), i) - luch.begin());
        res += (por[i] >= k-1 && b[k-1].second <= i ? 1 : 0);
        res += (por[i] < k-1 ? 1 : 0);
        ans = max(ans, res);
    }
    cout << ans + k - 1;
}
