function main(input) {
    input = input.split("\n");
    var n = parseInt(input[0].split(" ")[0]);
    var k = parseInt(input[0].split(" ")[1]);
    var values = input[1].split(" ").map(i => parseInt(i));

    var result = 0;
    for (var i = k; i >= 0; i--) {
        var cloneValues = values.concat();
        var lefts = i > 0 ? cloneValues.splice(0, i) : [];
        var m = Math.min(k - i, cloneValues.length);

        while(m >= 0) {
            var restValues = cloneValues.concat();
            var rights = m > 0 ? restValues.splice(0 - m) : [];
            var totalArray = lefts.concat(rights);
            var sliceIndex = k - totalArray.length;
            totalArray.sort((a, b) => a - b);
            // console.log(lefts, rights, sliceIndex, totalArray)
            var minusCount = totalArray.filter((v) => 0 > v).length;
            var o = 0;
            while (sliceIndex - 2 * o > 0) {
                var s = sliceIndex - 2 * o;
                var a = totalArray.concat();
                if (a.length <= s) {
                    o++
                    continue;
                }
                a.splice(0, s);
                result = Math.max(total(a), result);
                o++
            }
            
            m--;
        }
    }

    console.log(result);
}

function total(nums) {
    // console.log(nums)
    return nums.reduce((a, c) => {return a + c}, 0);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));