import java.util.*

fun calc(work: LongArray, i: Int, k: Int): Long {
    Arrays.sort(work)
    var sum = 0L
    for (m in 0 until i) {
        val value = work[m];
        if (m < k - i) {
            if (value > 0) {
                sum += value
            }
        } else {
            sum += value
        }
    }
    return sum
}

fun main(args: Array<String?>) {
    val scanner = Scanner(System.`in`)

    val n = scanner.nextInt()
    val k = scanner.nextInt()
    val values = LongArray(n)
    for (i in 0 until n) {
        values[i] = scanner.nextLong()
    }

    var max = 0L
    val start = Math.max(1, k / 2)
    for (i in start..k) {
        if (i <= (n - 1)) {
            val work = LongArray(i)
            for (j in 0..i) {
                var wi = 0
                for (l in 0 until j) {
                    work[wi++] = values[l]
                }
                for (l in 0 until (i - j)) {
                    work[wi++] = values[n - l - 1]
                }
                max = Math.max(calc(work, i, k), max)
            }
        } else {
            max = Math.max(calc(values, n, k), max)
            break;
        }
    }
    println(max)
}