fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map(String::toLong)
    val A = readLine()!!.split(" ").map(String::toLong)
    val b0 = LongArray(41)
    val b1 = LongArray(41)
    val acc = LongArray(41)
    var b = 1L
    for (i in 0 until 41) {
        var c0 = 0L
        var c1 = 0L
        for (a in A) {
            if (((a shr i) and 1) == 1L) ++c1
            else ++c0
        }
        b0[i] = c0 * b
        b1[i] = c1 * b
        if (i > 0) {
            acc[i] += acc[i-1]
        }
        acc[i] += Math.max(c0, c1) * b
        b *= 2
    }
    (acc.joinToString(" "))
    var tmp = 0L
    val cand = mutableListOf<Long>()
    cand.add(0)
    for (i in 40 downTo 0) {
        b /= 2
        if ((K and b) == 0L) {
            tmp += b1[i]
        } else {
            if (i > 0) {
                cand.add(tmp + b1[i] + acc[i - 1])
            } else {
                cand.add(tmp + b1[i])
            }
            tmp += b0[i]
        }
    }
    println(Math.max(tmp, cand.max()!!))
}