import java.lang.Math.min

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val dequeue = readLine()!!.split(" ").map(String::toInt).toIntArray()

    var ans = 0
    val r = min(n, k)
    for (a in 0 .. r) {
        for (b in 0 .. (r - a)) {
            val c = k - (a + b)
            val hand = dequeue.sliceArray(0 until a) + dequeue.sliceArray((n - b) until n)
            hand.sort()
            for (i in 0 until hand.size) {
                if (i >= c) {
                    break
                }
                if (hand[i] < 0) {
                    hand[i] = 0
                }
            }
            val sum = hand.sum()
            if (ans < sum) {
                ans = sum
            }
        }
    }

    println(ans)
}
