import java.math.*

fun main(args: Array<String>) {
    val (n, k) = readInputLine().split(" ").map{it.toInt()}
    val vArr = readInputLine().split(" ").map{it.toInt()}.toIntArray()
    
    var max = 0
    
    for (i in 0..Math.min(n, k)) {
        for (j in 0..Math.min(n - i, k - i)) {
            val list = mutableListOf<Int>()
            for (l in 0 until i) {
                list.add(vArr[l])
            }
            for (l in 0 until j) {
                list.add(vArr[n - l - 1])
            }
            list.sort()
            
            for (l in 0 until k - i - j) {
                if (list.isEmpty()) {
                    break
                }
                if (list.first() < 0) {
                    list.removeAt(0)
                } else {
                    break
                }
            }

            val sum = list.sum()
            if (sum > max) {
                max = sum
            }
        }
    }
    
    println(max)
}

fun readInputLine(): String {
    return readLine()!!
}
