import java.util.*

fun main(args:Array<String>){
    val (n,k) = readLine()!!.split(" ").map{it.toInt()}
    val v = readLine()!!.split(" ").map{it.toInt()}
    var ans = 0
    for(i in 0 .. n){
        for(j in 0 .. n){
            if(i + j > n || i + j > k) break
            val a = ArrayList<Int>()
            for(l in 0 until i) a.add(v[l])
            for(l in 0 until j) a.add(v[n - 1 - l])
            a.sort()
            var sum = a.sum()
            for(l in 0 until Math.min(k - (i + j), i + j)){
                if(a[l] < 0) sum -= a[l]
            }
            ans = Math.max(ans, sum)
        }
    }
    println(ans)
}
