object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, K = sc.nextInt
    val V = List.fill(N)(sc.nextLong)

    val minTake = if (K % 2 == 0) K / 2 else K / 2 + 1
    var result = 0L
    for (i <- minTake to K) {
      val maxDiscard = K - i
      for (left <- 0 to i) {
        val right = i - left
        val taken = (V.take(left) ++ V.takeRight(right)).sorted
        val minusCount = taken.count(_.<(0))
        val value = if (minusCount < maxDiscard) {
          taken.filter(_.>(0)).sum
        } else {
          taken.drop(maxDiscard).sum
        }
        if (result < value) {
          result = value
        }
      }
    }
    println(result)
  }
}