#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 12;

#define int long long

mt19937_64 rng (time (0));
int n, k, a[N], used[N];
int ans = 0, sum = 0;
vector<int> val;
int s2 = 0;
signed main() {
#ifdef local
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // local
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    int all = 0;
    for (int i = 1; i <= n; ++i) cin >> a[i], all += a[i];
    for (int posmx = 1; posmx <= n; ++posmx) {
        vector<int> le, ri;
        for (int i = 1; i < posmx; ++i) le.push_back (a[i]);
        for (int i = posmx + 1; i <= n; ++i) ri.push_back (a[i]);
        sort (begin (le), end (le));
        sort (begin (ri), end (ri));
        int sum = a[posmx];
        int idL = 0, idR = 0, now = 1, cntL = 0;
        while (now < n - k + 1) {
            if (idL != (int)le.size() && idR != (int)ri.size()) {
                if (le[idL] <= ri[idR] + 1 && le[idL] <= a[posmx] + cntL + 2) {
                    sum += le[idL];
                    ++idL;++now;
                    cntL++;
                }
                else if (ri[idR] <= a[posmx] + cntL + 1) {
                    sum += ri[idR];
                    idR++, ++now;
                } else break;
            } else if (idL < (int)le.size()) {
                if (le[idL] <= a[posmx] + cntL + 2) {
                    sum += le[idL];
                    ++idL;++now;
                    cntL++;
                } else break;
            } else if (idR < (int)ri.size()) {
                if (ri[idR] <= a[posmx] + cntL + 1) {
                    sum += ri[idR];
                    idR++, ++now;
                } else {
                    break;
                }
            } else break;
        }
        if (now == n - k + 1) {
            ans = max (ans, (k - 1) + all - sum + a[posmx] + cntL + 1);
        }
    }

    cout << ans << '\n';
}
