import java.util.Scanner
import java.lang.Long.parseLong


// reverse binary //

object Main extends App {
  val sc = new Scanner(System.in)

  val N = sc.nextInt(); val K = sc.nextLong().toBinaryString.reverse

  val nums = new Array[(String, Int)](N)  // (binary, value)

  for(i <- 0 until N) {
    val a = sc.nextLong().toBinaryString.reverse
    val b = sc.nextInt()
    nums(i) = (a, b)
  }

  var ans = 0L

  // 最上位たてない
  for((bi, v) <- nums) {
    if (bi.length < K.length)
      ans += v
  }

  // on top
  var tmp = 0L
  for((bi, v) <- nums) {
    if (bi.length <= K.length) {
      var flag = true
      for (i <- 0 until bi.length) {
        if (bi(i) > K(i))
          flag = false
      }
      if (flag)
        tmp += v
    }
  }
  ans = Math.max(ans, tmp)

  // all loop
  for (i <- (0 until K.length - 1).reverse) {
    var tmp = 0L
    for((bi, v) <- nums) {
      if (bi.length > K.length || K(i) == '0')
        ()
      else if (bi.length <= i) {
        tmp += v
      }
      else if (bi.length == i)
        ()
      else {
        var flag = true
        if (bi(i) == '1')
          flag = false
        for(k <- i+1 until bi.length) {
          if (bi(k) > K(k))
            flag = false
        }
        if (flag)
          tmp += v
      }
    }
    ans = Math.max(ans, tmp)

    //println(s"${i}  ${ans}")
  }

  println(ans)
}
