import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  val (n, k) = readIs()
  val m = min(n, k)
  val vv = readIs()
  var ans = 0
  for (i in 0..m) {
    var suml = 0
    val negl = mutableListOf<Int>()
    for (ii in 0 until i) {
      suml += vv[ii]
      if (vv[ii] < 0) negl += vv[ii]
    }
    for (j in 0..(m - i)) {
      var sum = suml
      val neg = ArrayList(negl)
      for (jj in n - j until n) {
        sum += vv[jj]
        if (vv[jj] < 0) neg += vv[jj]
      }
      val sneg = neg.sorted()
      for (h in 0 until min(sneg.size, k - i - j)) {
        sum -= sneg[h]
      }
      ans = max(ans, sum)
    }
  }
  println(ans)
}
