import java.util.*
 
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map(String::toInt)
    val V = readLine()!!.split(" ").map(String::toLong).toList()
    var ans = 0L
 
    for (l in 0..K) {
        for (r in 0..K-l) {
            if (l+r > N) break
            val list = mutableListOf<Long>()
            list.addAll(V.subList(0,l))
            list.addAll(V.subList(N-r,N))
            val ng = list.count{it<0}
            list.sort()
            val sum = list.drop(Math.min(ng,K-l-r)).sum()
            ans = Math.max(ans,sum)
        }
    }
    println(ans)
}