#include <bits/stdc++.h>
using namespace std;
const int maxn = 111;
int f[maxn][maxn][maxn], g[maxn][maxn][maxn], a[maxn];
int solve(int l, int r, int op){
	if(op == 0) return 0;
	if(l > r) return 0;
	int & ans = f[l][r][op];
	if(g[l][r][op]) return ans;
	ans = 0;
	ans = max(ans, a[l] + solve(l + 1, r, op - 1));
	ans = max(ans, a[r] + solve(l, r - 1, op - 1));
	if(op > 1) ans = max(ans, solve(l + 1, r, op - 2));
	if(op > 1) ans = max(ans, solve(l, r - 1, op - 2));
	g[l][r][op] = 1;
	return ans;
}
int main(){
	int n, k; cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> a[i];
	cout << solve(0, n - 1, k) << endl;
	return 0;
}

