#include <bits/stdc++.h>

using namespace std;

#define int long long

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