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

alias T = Tuple!(long, long, long);
long[T] memo;
long n, k;

long f(long[] vs, long l, long r, long m) {
	auto key = tuple(l, r, m);
	if (key in memo) return memo[key];
	if (m < 0) 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 = m > 1 ?     f(vs, l+1, r  , m-2) : int.min;
	auto x4 = m > 1 ?     f(vs, l  , r+1, m-2) : int.min;
	auto v = max(x1, x2, x3, x4, 0);
	memo[key] = v;
	return v;
}

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