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

void main() {
    long n, k;
    readf("%d %d\n", &n, &k);

    long[] vs = readln.strip.split(" ").map!(to!long).array;

    long solve(long c, long l, long r) {
        long[] xs = [0];
        if (c > 0 && l <= r) {
            xs ~= solve(c - 1, l + 1, r) + vs[l];
            xs ~= solve(c - 1, l, r - 1) + vs[r];
        }
        if (c > 1 && l <= r) {
            xs ~= solve(c - 2, l + 1, r);
            xs ~= solve(c - 2, l, r - 1);
        }
        return xs.maxElement;
    }
    writeln(solve(k, 0, n-1));
}

