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

    var ans = 0
    for(take in 0..Math.min(n,k)){
        for(takeL in 0..take) {
            val takeR = take-takeL
            var remove = k-take
            if(remove<0) remove = 0
            if(remove>take) remove = take
            var count = 0
            val vv = (v.take(takeL)+v.takeLast(takeR)).sorted().dropWhile { ++count<=remove && it<0 }
            ans = Math.max(ans, vv.sum())
        }
    }
    println(ans)
}
