fun main(args: Array<String>) {
    val (n, K) = listOfLong()
    val N = n.toInt()
    val A = listOfLong()
    var x = 0L
    val DIGIT = 40
    for (i in DIGIT - 1 downTo 0) {
        var count = 0
        for (j in 0 until N) count += 1 and (A[j] shr i).toInt()
        if (count <= N / 2) if ((x or (1L shl i)) <= K) x = x or (1L shl i)
    }
    var sum = 0L
    for (i in 0 until N) sum += x xor A[i]
    println(sum)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map(String::toLong)