

#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 = -1, idR = -1, now = 1, cntL = 0;
        if (k != n) {
            if (posmx == n) idL =  n - k - 1;
            else if (posmx == 1) idR = n - k - 1;
            else {
                if ((int)le.size() + (int)ri.size() == n - k) idL = (int)le.size() - 1, idR = (int)ri.size() - 1;
                else if (n - k <= (int)ri.size() && ri[n - k - 1] <= le[0]) {
                    idR = n - k - 1;
                }
                else if (n - k <= (int)le.size() && le[n - k - 1] <= ri[0]) idR = n - k - 1;
                else {
                    for (int i = 0; i < (int)le.size(); ++i) {
                        int j = n - k - i - 2;
                        if (j >= (int)ri.size() || j < 0) continue;
                        if ((j == (int)ri.size() - 1 || le[i] <= ri[j + 1]) && (i == (int)le.size() - 1 || ri[j] <= le[i + 1])) {
                            idL = i, idR = j;
                            break;
                        }
                    }
    //                int l = 1, r = min (n - k, posmx - 1);
    //                while (l < r) {
    //                    int mid = (l + r + 1) >> 1;
    //                    int ps = n - k - mid;
    //                    if (ps > (int)ri.size()) {
    //                        l = mid + 1;
    //                    } else {
    //                        if (le[mid - 1] <= ri[ps] && ri[ps - 1] <= le[mid]) l = mid;
    //                        else r = mid - 1;
    //
    //                }
    //                idL = l - 1;
    //                idR = n - k - l - 1 - 1;
                }
            }
        }
        for (int i = 0; i <= idL; ++i) sum += le[i];
        for (int i = 0; i <= idR; ++i) sum += ri[i];
        ans = max (ans, (k - 1) + all - sum + a[posmx] + idL + 2);
    }

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