import std.stdio, std.string, std.conv, std.algorithm;
void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], k = tmp[1];
    int[] v = readln.split.to!(int[]);
    int maxv;
    foreach (i; 0 .. n+1) {
        foreach (j; 0 .. n+1) {
            if (i + j > min(n, k)) break;
            int[] s = v[0..i] ~ v[n-j..$];
            s.sort!"a < b";
            int cnt = s.count!"a < 0".to!int;
            if (cnt <= k - i - j) {
                maxv = max(maxv, s[cnt..$].sum);
            } else {
                maxv = max(maxv, s[k-i-j..$].sum);
            }
        }
    }
    maxv.writeln;
}