#include <bits/stdc++.h>

using namespace std;
typedef long long ll;


void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) cin >> a[i];
    vector<ll> b = a;
    sort(b.begin(), b.end());
    ll answer1 = 0;
    for (ll i = n - 1; i > n - k; --i) answer1 += b[i];
    ll maxp = 0;
    map<ll, ll> maxpos;
    for (ll i = 0; i < n; ++i) maxpos[a[i]] = i;
    for (int i = n - k + 1; i < n; ++i) maxp = max(maxp, maxpos[b[i]]);
    ll answer = 0;
    for (int i = 0; i < n - k + 1; ++i) {
        answer = max(answer, answer1 + max(maxp, maxpos[b[i]]) + 1 + b[i]);
    }
    cout << answer << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t = 1;
    // cin >> t;
    while (t--) solve();
}
