object Main extends App {
  val input = io.Source.stdin.getLines.toIndexedSeq.map(_.split(' ').map(_.toInt).toIndexedSeq)
  val K = input(0)(1)
  //println(K)
  val in = input(1)
  //println(in)

  var sums=Seq[Long]()
  (0 until in.size).foreach{ i =>
    (i until in.size).foreach{ j =>
      val sub = (i to j).map(k => in(k).toLong).sum
      sums +:= sub
    }              
  }
  //println(sums)
  val rs = sums.sorted.reverse
  //println(rs)
  val tk = rs.take(K)
  val and = tk.foldLeft(-1L){ (a,e)=>
    a & e
  }
  println(and)
}
