fun main(arg: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map(String::toInt)
    val po = readLine()!!.split(' ').map(String::toInt)
    val score = (0..k).map { left ->
        (0..Math.min(k - left, n - left)).map { right ->
            val meu = (po.take(left) + po.drop(n - right)).sorted()
            val minus = meu.take(k - left - right).takeWhile { it < 0 }
            meu.sum() - minus.sum()
        }.max() ?: 0
    }.max() ?: 0
    println(score)
}
