import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int k, int[] v) {
    int n = cast(int)v.length;
    int ans = 0;

    // 左から a 個とる
    for (int a = 0; a <= min(n, k); a++) {
        // 右から b 個とる
        for (int b = 0; b <= min(n, k) - a; b++) {
            int[] w;
            foreach (i; 0..a) w ~= v[i];
            foreach (i; 0..b) w ~= v[n-1-i];

            int val = w.sum;
            int restK = max(0, k - (a + b));
            if (restK > 0) {
                w.sort();
                // writeln("restK ", restK, " ", w);
                val += -w.until!("a >= 0").take(restK).sum;
            }
            ans = max(ans, val);
        }
    }
    return ans;
}

void main() {
    int n, k; scan(n, k);
    auto v = readints;
    writeln(calc(k, v));
}
