fun main(args :Array<String>) {
    val (n, k) = readIntegerList()
    val vList = readIntegerList()
    var ans = 0
    for (left in 0..Math.min(n, k)) {
        for (right in 0..Math.min(k - left, n - left)) {
            val sum = (vList.subList(0, left) + vList.subList(n - right, n))
                .sorted()
                .filterIndexed { index, v ->
                    if (index >= k - left - right) {
                        true
                    } else if (v < 0) {
                        false
                    } else {
                        true
                    }
                }.sum()
            ans = Math.max(ans, sum)
        }
    }

    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
