#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<pair<ll, ll>> a1;
    for (ll i = 0; i < n; i++) {
        a1.push_back({a[i], i});
    }
    sort(a1.rbegin(), a1.rend());
    set<ll> s1;
    ll answer = 0;
    for (ll i = 0; i < k - 1; i++) {
        answer += a1[i].first + 1;
        s1.insert(a1[i].second);
    }
    vector<ll> b;
    for (ll i = 0; i < n; i++) {
        if (s1.find(i) == s1.end()) {
            b.push_back(a[i]);
        }
    }
    ll max1 = 0;
    for (ll i = 0; i < b.size(); i++) {
        max1 = max(max1, b[i] + i + 1);
    }
    answer += max1;
    if (k != n) {
        for (ll i = 0; i < k; i++) {
            s1.erase(a1[i].second);
            s1.insert(a1[k].second);
            vector<ll> b1;
            ll answer1 = 0;
            for (ll j = 0; j < n; j++) {
                if (s1.find(j) == s1.end()) {
                    b1.push_back(a[j]);
                } else {
                    answer1 += a[j];
                }
            }
            ll max2 = 0;
            for (ll j = 0; j < b.size(); j++) {
                max2 = max(max2, b[j] + j + 1);
            }
            answer1 += max2;
            s1.insert(a1[i].second);
            s1.erase(a1[k].second);
            answer = max(answer, answer1);
        }
    }
    cout << answer;
}