local mfl = math.floor
local n, k = io.read("*n", "*n")
local as, bs = {}, {}
local kdigs = {}
do
  local tk = k
  for i = 1, 32 do
    kdigs[i] = tk % 2
    tk = mfl(tk / 2)
  end
end
local klim = 1
for i = 32, 1, -1 do
  if kdigs[i] == 1 then
    klim = i
    break
  end
end

local digs = {}
local maxdig = {}
for i = 1, n do
  digs[i] = {}
  local a = io.read("*n")
  bs[i] = io.read("*n")
  for j = 1, 32 do
    digs[i][j] = a % 2
    a = mfl(a / 2)
  end
  maxdig[i] = 1
  for j = 32, 1, -1 do
    if digs[i][j] == 1 then
      maxdig[i] = j
      break
    end
  end
end

local ret = 0
local mma = math.max
for lim = 0, klim do
  if lim == 0 or kdigs[lim] == 1 then
    local score = 0
    for i = 1, n do
      local isok = maxdig[i] <= klim
      for dig = 1, klim do
        if dig < lim then
          -- nothing
        elseif dig == lim then
          if digs[i][dig] == 1 then isok = false break end
        else
          if kdigs[dig] < digs[i][dig] then isok = false break end
        end
      end
      if isok then score = score + bs[i] end
    end
    ret = mma(ret, score)
  end
end
print(ret)
