object Main {
  def main(args: Array[String]): Unit = {
    val K = readLine().split(" ").toList.map(_.toInt) match {
      case n :: k :: _ => k
    }

    val numLst = readLine().split(" ").toList.map(_.toInt)

    def generate(lst: List[Int], count: Int = K, result: List[Int] = List(numLst.sum)): List[Int] = if (count != 0) lst match {
      case Nil => result.dropRight(1)
      case int :: tail => generate(tail, count - 1, result.head - int :: result)
    } else result.dropRight(1)

    println((numLst.sum :: generate(numLst) ::: generate(numLst.reverse)).sorted.reverse.take(K).reduce((cur, prev) => prev & cur))
  }
}