fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toInt()}
    val V = readLine()!!.split(" ").map{it.toLong()}

    val sum = V.sum()
    var res = 0L

    for (numPoll in 0.. Math.min(N, K)) {
        for (lPoll in 0..numPoll) {
            val list = V.take(lPoll) + V.takeLast(numPoll - lPoll)
            val negList = list.filter { it < 0 }.sorted().take(K - numPoll)

            val ans = list.sum() - negList.sum()
            res = Math.max(res, ans)
        }
    }

    println(res)
}
