fun main(args: Array<String>) {
    val (N, K) = listOfInt()
    val L = listOfInt()
    val R = L.asReversed()
    val nk = Math.min(N, K)
    var ans = Long.MIN_VALUE
    for (A in 0 .. nk) {
        for (B in 0 .. nk - A) {
            val v = mutableListOf<Int>()
            for (l in 0 until A) v.add(L[l])
            for (r in 0 until B) v.add(R[r])
            v.sort()
            val k = Math.min(K - (A + B), v.count { it < 0 })
            val d = v.drop(k).sumByDouble { it.toDouble() }.toLong()
            if (ans < d) ans = d
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)