import java.util.*
import kotlin.comparisons.*

fun main(args : Array<String>) {
  val (n, k) = readLine()!!.split(' ').map(String::toInt)
  val vv = readLine()!!.split(' ').map(String::toLong)
  val h = Math.min(n, k)
  var ans = 0L
  for (l in 0..h) {
    for (r in 0..h - l) {
      val s = (vv.subList(0, l) + vv.subList(n - r, n)).sorted()
      var sum = s.sum()
      val d = k - l - r
      for (i in 0 until d) {
        if (s.size <= i || 0 < s[i]) break
        sum -= s[i]
      }
      ans = Math.max(ans, sum)
    }
  }
  println(ans)
}
