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

    var max = 0
    (0..Math.min(N, K)).forEach {L ->
        (0..Math.min(N, K)).forEach { R ->
            if (L +R <= Math.min(N, K)) {
                val popped = mutableListOf<Int>()
                if (L > 0) {
                    V.slice(0..(L-1)).forEach {
                        popped.add(it)
                    }
                }
                if (R > 0) {
                    V.slice((N-R)..(N-1)).forEach {
                        popped.add(it)
                    }
                }

                popped.sort()
                val timesPossibleToReturn = K - (L+R)
                var sum = popped.sum()
                if (timesPossibleToReturn > 0) {
                    popped.take(timesPossibleToReturn).filter { it < 0 }.forEach {
                        sum -= it
                    }
                }

                max = Math.max(sum, max)
            }
        }
    }
    println(max)
}