import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N, K;
    scan(N, K);
    auto V = aryread();
    long ans = long.min;
    long M = min(N, K);
    foreach (x; 0 .. M + 1)
        foreach (y; 0 .. M - x + 1)
        {
            auto X = V[0 .. x];
            auto Y = V[N - y .. $];
            long t = X.sum() + Y.sum();
            auto r = chain(X, Y).array;
            r.sort();
            foreach (i; 0 .. M - (x + y))
                if (i < r.length && r[i] < 0)
                {
                    t -= r[i];
                }
                else
                {
                    break;
                }
            ans = ans.max(t);
        }
    writeln(ans);
}
