#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;

template<typename T>
istream& operator>>(istream& is, vector<T>& a) {
	for (auto& i : a) {
		is >> i;
	}
	return is;
}

mt19937 rng(228);

int32_t main() {
#ifdef LOCAL
	assert(freopen("C:\\Users\\User\\input.txt", "r", stdin));
#else
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#endif
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	cin >> a;
	ll ans = 0;
	vector<vector<int>> bb;
	auto calc = [&](auto calc, int pos) -> void {
		if (pos == n && (int)bb.size() == k) {
			ll cur = 0;
			for (int i = 0; i < k; ++i) {
				int mx = 0;
				for (int j = 0; j < (int)bb[i].size(); ++j) {
					mx = max(mx, bb[i][j] + j + 1);
				}
				cur += mx;
			}
			ans = max(ans, cur);
			return;
		}
		if (pos == n) {
			return;
		}
		for (int i = 0; i < (int)bb.size(); ++i) {
			bb[i].push_back(a[pos]);
			calc(calc, pos + 1);
			bb[i].pop_back();
		}
		if (bb.empty() || (!bb.empty() && !bb.back().empty())) {
			bb.push_back({});
			bb.back().push_back(a[pos]);
			calc(calc, pos + 1);
			bb.back().pop_back();
			bb.pop_back();
		}
	};
	calc(calc, 0);
	cout << ans << "\n";
	return 0;
}