object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._

//    val Array(n, m) = readLine().split(" ").map(_.toInt)
//    val KS: Array[(Int, Array[Int])] = (0 until m). map { i =>
//      val Array(k, s @ _*) = readLine().split(" ").map(_.toInt)
//      (k, s.toArray)
//    }. toArray
//    val P = readLine().split(" ").map(_.toInt)

    val Array(_n, _k) = readLine().split(" ").map(_.toInt)
    val N = _n
    val K = _k
    val V = readLine().split(" ").map(_.toInt)

    //　K回目の操作の時に, Vl ~ Vrのうちから取り出す最大価値
    def solve(k: Int, l: Int, r: Int): Int =
      if (k <= 0 || l < 0 || l >= N || r < 0 || r >= N || l > r) 0 // 残り操作回数が0回以下なら0
      else
        Math.max(
          Math.max(solve(k - 2, l + 1, r), solve(k - 1, l + 1, r) + V(l)),
          Math.max(solve(k - 2, l, r - 1), solve(k - 1, l, r - 1) + V(r)))

    println(solve(K, 0, N-1))
  }
}