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
  var i=0
  while(i < sz){
    var j=i
    while(j < sz){
      var k=i
      var sub=0L
      while(k <= j){
        sub += in(k)
        k += 1
      }
      sums = sub :: sums
      j += 1
    }
    i += 1
  }
  //println(sums)
  val rs = sums.toArray.sorted.toArray
  //println(rs)
  //val tk = rs.takeRight(K)
  var k=rs.size-K
  var and = -1L
  while(k < rs.size){
    and &= rs(k)
    k += 1
  }
  println(and)
}
