import bisect

import copy

import heapq

import math

import sys

from collections import *

from itertools import accumulate, combinations, permutations, product

from math import gcd

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

mod=pow(10,9)+7

al=[chr(ord('a') + i) for i in range(26)]

direction=[[1,0],[0,1],[-1,0],[0,-1]]



n,k=list(map(int,input().split()))

ab=[list(map(int,input().split())) for i in range(n)]



ans=0

ab.sort()

m=bin(k)

# print(m)

klst=[m]

for i in range(2,len(m)):

    if m[i]=="1":

        klst.append(m[:i]+"0"+"1"*(len(m)-i-1))



# print(klst)

for i in klst:

    tmp=0

    for j in range(n):

        a,b=ab[j]

        if a|int(i,0)==int(i,0):

            tmp+=b

    ans=max(ans,tmp)

print(ans)
import bisect

import copy

import heapq

import math

import sys

from collections import *

from itertools import accumulate, combinations, permutations, product

from math import gcd

def input():

    return sys.stdin.readline()[:-1]

def ruiseki(lst):

    return [0]+list(accumulate(lst))

mod=pow(10,9)+7

al=[chr(ord('a') + i) for i in range(26)]

direction=[[1,0],[0,1],[-1,0],[0,-1]]



n,k=list(map(int,input().split()))

ab=[list(map(int,input().split())) for i in range(n)]



ans=0

ab.sort()

m=bin(k)

# print(m)

klst=[m]

for i in range(2,len(m)):

    if m[i]=="1":

        klst.append(m[:i]+"0"+"1"*(len(m)-i-1))

for i in range(len(klst)):

    klst[i]=int(klst[i],0)

# print(klst)

for i in klst:

    tmp=0

    for j in range(n):

        a,b=ab[j]

        if a|i==i:

            tmp+=b

    ans=max(ans,tmp)

print(ans)
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd


def input():
    return sys.stdin.readline()[:-1]


def ruiseki(lst):
    return [0] + list(accumulate(lst))


mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n, k = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
ans = 0
ab.sort()
m = bin(k)
# print(m)
klst = [m]
for i in range(2, len(m)):
    if m[i] == "1":
        klst.append(m[:i] + "0" + "1" * (len(m) - i - 1))
# print(klst)
for i in klst:
    tmp = 0
    for j in range(n):
        a, b = ab[j]
        if a | int(i, 0) == int(i, 0):
            tmp += b
    ans = max(ans, tmp)
print(ans)

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd


def input():
    return sys.stdin.readline()[:-1]


def ruiseki(lst):
    return [0] + list(accumulate(lst))


mod = pow(10, 9) + 7
al = [chr(ord("a") + i) for i in range(26)]
direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]
n, k = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(n)]
ans = 0
ab.sort()
m = bin(k)
# print(m)
klst = [m]
for i in range(2, len(m)):
    if m[i] == "1":
        klst.append(m[:i] + "0" + "1" * (len(m) - i - 1))
for i in range(len(klst)):
    klst[i] = int(klst[i], 0)
# print(klst)
for i in klst:
    tmp = 0
    for j in range(n):
        a, b = ab[j]
        if a | i == i:
            tmp += b
    ans = max(ans, tmp)
print(ans)

+for i in range(len(klst)): +    klst[i] = int(klst[i], 0) -        if a | int(i, 0) == int(i, 0): +        if a | i == i: