fun main(arg: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map(String::toInt)
    val po = readLine()!!.split(' ').map(String::toInt)
    var score = -1000000000
    (0..k).forEach { i1 ->
        (0..Math.min(i1, n)).forEach { i2 ->
            (0..i2).forEach { i3 ->
                val meu = (po.take(i3) + po.drop(n - (i2 - i3))).sorted().drop(i1 - i2).sum()
                score = Math.max(score, meu)
            }
        }
    }
    println(score)
}
