import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

long[100^^3] memo;
long n, k;

long f(long[] vs, long l, long r, long m) {
	auto midx = l*10000 + r*100 + m;
	if (memo[midx] != long.min) return memo[midx];
	if (m < 0 || vs.length-r-1 == l) return 0;
	auto x1 = vs[l] + f(vs, l+1, r, m-1);
	auto x2 = vs[$-r-1] + f(vs, l, r+1, m-1);
	auto x3 = f(vs, l+1, r, m-2);
	auto x4 = f(vs, l, r+1, m-2);
	auto v = max(x1, x2, x3, x4);
	memo[midx] = v;
	return v;
}

void main() {
	scanf("%ld %ld\n", &n, &k);
	foreach(i; 0..100^^3) {
		memo[i] = long.min;
	}
	auto vs = readln.chomp.split.to!(long[]);
	f(vs, 0, 0, k-1).write;
}
