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

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, k, cost;
    scan(n, k);
    auto v = aryread();
    foreach (take; iota((k + 1) / 2, min(k, n) + 1))
    {
        foreach (left; iota(take + 1))
        {
            auto ret = k - take;
            auto jewel = new long[](0);
            foreach (i; iota(left))
                jewel ~= v[i];
            foreach (j; iota(take - left))
                jewel ~= v[n - 1 - j];

            jewel.sort!"a>b"();
            while (ret > 0 && jewel[$ - 1] < 0)
                jewel.length--, ret--;
            cost = max(jewel.sum(), cost);
        }
    }
    cost.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
