fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map{it.toInt()}
    val P = Array(N) { readLine()!!.split(" ").map{it.toLong()}}

    fun calc(mask: Long): Long {
        return P.filter { it[0] and mask == it[0] }
            .map {it[1]}
            .sum()
    }

    var res = calc(K.toLong())

    for (i in 1 until 30) {
        if (K and (1 shl i) == 0) {
            continue
        }

        val mask = (K and (1 shl i).inv()) or ((1 shl i) - 1)
        res = Math.max(res, calc(mask.toLong()))
    }

    println(res)
}
