#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <iomanip>
using namespace std;
using ll = long long;
using ld = long double;
#define endl '\n'
vector<int> f;
ll solve(int n, int k, vector<int> v) {
	if (!k) return -1e18;
	ll res = -1e18;
	vector<int> mx(n); mx[n - 1] = v[n - 1] + n - 1;
	for (int i = n - 2; i >= 0; i--) mx[i] = max(mx[i + 1], v[i] + i);
	for (int i = k - 1; i < n; i++) {
		if (mx[i] != v[i] + i) continue;
		int val = v[i] + i - (k - 1);
		vector<int> bd;
		for (int j = 0; j < i; j++) {
			int val1 = v[j] + j - bd.size();
			if (val1 > val) bd.push_back(j);
		}
		if (bd.size() >= k) {
			vector<int> vv;
			for (auto el : bd) vv.push_back(v[el]); ll val0 = v[i] + i - bd.size() + 1;
			res = max(res, val0 + solve(bd.size(), k - 1, vv)); continue;
		}
		ll sum = val + 1;
		for (auto j : bd) sum += v[j] + 1;
		vector<int> v1; int j = 0;
		for (int p = 0; p < i; p++) {
			if (j < bd.size() && p == bd[j]) {
				j++; continue;
			}
			v1.push_back(p);
		}
		sort(v1.rbegin(), v1.rend());
		for (int p = 0; p < k - 1 - bd.size(); p++) sum += v[v1[p]] + 1;
		res = max(res, sum);
	}
	return res;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k; vector<int> v(n);
	for (auto& i : v) cin >> i;
	cout << solve(n, k, v);
	return 0;
}
