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

int f(int[] vs, int l, int r, int k) {
	if (k <= 0 || vs.length-r-1 == l) return 0;
	auto x1 = vs[l] + f(vs, l+1, r, k-1);
	auto x2 = vs[$-r-1] + f(vs, l, r+1, k-1);
	auto x3 = vs[l] < 0 ? f(vs, l+1, r, k-2) : int.min;
	auto x4 = vs[$-r-1] < 0 ? f(vs, l+1, r, k-2) : int.min;
	return max(x1, x2, x3, x4);
}

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