fun main(args: Array<String>) {
    val (n, k) = readInputLine().split(" ").map { it.toInt() }
    val aList = readInputLine().split(" ").map { it.toLong() }
    
    var sumList = mutableListOf<Long>()
    
    for (i in 0 until n) {
        var sum = aList[i]
        sumList.add(sum)
        for (j in i + 1 until n) {
            sum += aList[j]
            sumList.add(sum)
        }
    }
    
    sumList.sortDescending()
    
    var bitFlag = 1L.shl(50)
    
    while (bitFlag != 0L) {
        val filtered = sumList.filter { it and bitFlag != 0L}
        if (filtered.size >= k) {
            sumList = filtered.toMutableList()
        }
        bitFlag = bitFlag.shr(1)
    }
    
    var ans = sumList[0]
    for (i in sumList) {
        ans = ans and i
    }
    
    println(ans)
}
 
fun readInputLine(): String {
    return readLine()!!
}
