#include <bits/stdc++.h>

using ll = long long;

using namespace std;

#define int ll

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    set<pair<int, int>> st;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st.insert({a[i], i});
    }

    vector<int> mx_pos(n, 1);
    int sm = 0;
    while (st.size() != n - k + 1) {
        mx_pos[st.rbegin()->second] = 0;
        sm += st.rbegin()->first;
        st.erase(--st.end());
    }

    int ans = 0;

    int cur = 0;
    for (int i = 0; i < n; i++) {
        if (!mx_pos[i]) {
            continue;
        }
        cur += mx_pos[i];
        ans = max(ans, k - 1 + sm + a[i] + cur);
    }

    cout << ans;

    cout << "\n";
    return 0;
}