#include <bits/stdc++.h>

using namespace std;

#define int long long

mt19937_64 rng(777);

signed main() {
//    while (1) {
        int n = rng() % 100 + 1, k = rng() % n + 1;
//        cout << n << " " << k << "\n";
    cin >> n >> k;
        vector<pair<int, int>> a(n);
//        a[0] = {rng() % (int) 100, 0};
        for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
//            a[i] = {a[i - 1].first + rng() % 20 - 1, i};
        }
//        for (auto el: a) {
//            cout << el.first << " ";
//        }
//        cout << "\n";
        vector<pair<int, int>> b = a;
        sort(b.begin(), b.end());
//        int sum1 = a.back().first + n;
//        int h = 0;
//        for (int i = n - 1; i > n - k - h; i--) {
//            if ((b[i].second != n - 1)) sum1 += b[i].first;
//            h = max(h, (int) (b[i].second == n - 1));
//        }
//        cout << sum1 << "\n";
        int best = 0;
        for (int i = 0; i < n; i++) {
            map<int, int> mp;
            int cur = a[i].first + 1;
            mp[a[i].second] = 1;
            int cnt = 1;
            int sum = a[i].first + 1;
            for (int j = i - 1; j > -1; j--) {
                best = max(best, sum);
                if (a[j].first > cur) {
                    cnt++;
                    if (cnt > k) {
                        break;
                    }
                    cur = a[j].first + 1;
                    sum += a[j].first;
                    mp[a[j].second] = 1;
                }
                sum++;
            }
//            cout << sum << " " << cnt << "\n";
            if (cnt > k) {
                continue;
            }
            int lol = 0;
            for (int j = n - 1; j > n - (k - cnt + 1) - lol; j--) {
                if (!mp[b[j].second]) {
                    sum += b[j].first;
                }
                lol += mp[b[j].second];
            }
            best = max(best, sum);
        }
        cout << best << "\n";
//        if (sum1 != best) break;
//    }
}
