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

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