fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toLong() }
    val A = readLine()!!.split(" ").map { it.toLong() }
    val dp = Array (60) { Array(2) { Array(2) { -1L } } }

    fun f(k: Int, u: Int, l: Int): Long {
        if (k < 0) {
            return 0
        }

        if (dp[k][u][l] >= 0) {
            return dp[k][u][l]
        }

        val s0 = A.map { (it and (1L shl k)) xor (0L shl k) }.sum()
        val s1 = A.map { (it and (1L shl k)) xor (1L shl k) }.sum()

        dp[k][u][l] = Math.max(dp[k][u][l], f(k - 1, Math.min(u, (K shr k).toInt().inv() and 1), l) + s0)

        if ((K shr k) and 1L == 1L || u == 0) {
            dp[k][u][l] = Math.max(dp[k][u][l], f(k - 1, u, Math.min(l, (K shr k).toInt() and 1)) + s1)
        }

        return dp[k][u][l]
    }

    println(f(59, 1, 0))
}
