unittest
{
	assert( [ "6 4", "-10 8 2 1 2 6" ].solve == 14 );
	assert( [ "6 4", "-6 -100 50 -2 -5 -3" ].solve == 44 );
	assert( [ "6 3", "-6 -100 50 -2 -5 -3" ].solve == 0 );
	
	assert( [ "6 8", "-10 8 2 1 2 -6" ].solve == 13 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	input.popFront;
	auto vs = input.front.split.to!( long[] );
	
	auto ans = long.min;
	foreach( c; 0L .. k + 1 )
	{
		auto cc = min( n, c );
		foreach( l; 0L .. cc + 1 )
		{
			foreach( r; 0L .. cc - l + 1 )
			{
				auto t = 0L;
				long[] ms;
				foreach( v; vs[ 0 .. l ] )
				{
					t += v;
					if( v < 0 ) ms ~= v;
				}
				foreach( v; vs[ $ - r .. $ ] )
				{
					t += v;
					if( v < 0 ) ms ~= v;
				}
				t -= ms.sort.take( c - l - r ).sum;
				ans = max( ans, t );
			}
		}
	}
	return ans;
}
