def issubset(x,y):

    #a<<bならtrue

    if len(x)>len(y):

        return False

    for i in range(1,len(x)+1):

        if (x[-i],y[-i])==("1","0"):

            return False

    return True

N,K=list(map(int,input().split()))

A=[0 for i in range(N)]

B=[0 for i in range(N)]

for i in range(N):

    A[i],B[i]=list(map(int,input().split()))

    A[i]=bin(A[i])[2:]

Ks=bin(K)[2:]

Kl=[Ks]

for i,c in enumerate(Ks):

    if c=="1":

        Kl.append(Ks[:i]+"0"+"1"*(len(Ks)-i-1))

ans=0

for k in Kl:

    tmp=0

    for i in range(N):

        if issubset(A[i],k):

            tmp+=B[i]

    ans=max(tmp,ans)

print(ans)

N,K=list(map(int,input().split()))

A=[0 for i in range(N)]

B=[0 for i in range(N)]

for i in range(N):

    A[i],B[i]=list(map(int,input().split()))

S=bin(K)

X=[K]

M=len(S)-2

for k in range(1,M+1):

    if S[-k]=="0":continue

    tmp=S[:-k]+"0"+"1"*(k-1)

    X.append(int(tmp,2))

ans=0

for n in X:

    tmp=0

    for i in range(N):

        if A[i]&n==A[i]:

            tmp+=B[i]

    ans=max(ans,tmp)

print(ans)

def issubset(x, y):
    # a<<bならtrue
    if len(x) > len(y):
        return False
    for i in range(1, len(x) + 1):
        if (x[-i], y[-i]) == ("1", "0"):
            return False
    return True


N, K = list(map(int, input().split()))
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))
    A[i] = bin(A[i])[2:]
Ks = bin(K)[2:]
Kl = [Ks]
for i, c in enumerate(Ks):
    if c == "1":
        Kl.append(Ks[:i] + "0" + "1" * (len(Ks) - i - 1))
ans = 0
for k in Kl:
    tmp = 0
    for i in range(N):
        if issubset(A[i], k):
            tmp += B[i]
    ans = max(tmp, ans)
print(ans)

N, K = list(map(int, input().split()))
A = [0 for i in range(N)]
B = [0 for i in range(N)]
for i in range(N):
    A[i], B[i] = list(map(int, input().split()))
S = bin(K)
X = [K]
M = len(S) - 2
for k in range(1, M + 1):
    if S[-k] == "0":
        continue
    tmp = S[:-k] + "0" + "1" * (k - 1)
    X.append(int(tmp, 2))
ans = 0
for n in X:
    tmp = 0
    for i in range(N):
        if A[i] & n == A[i]:
            tmp += B[i]
    ans = max(ans, tmp)
print(ans)

-def issubset(x, y): -    # a<<bならtrue -    if len(x) > len(y): -        return False -    for i in range(1, len(x) + 1): -        if (x[-i], y[-i]) == ("1", "0"): -            return False -    return True - - -    A[i] = bin(A[i])[2:] -Ks = bin(K)[2:] -Kl = [Ks] -for i, c in enumerate(Ks): -    if c == "1": -        Kl.append(Ks[:i] + "0" + "1" * (len(Ks) - i - 1)) +S = bin(K) +X = [K] +M = len(S) - 2 +for k in range(1, M + 1): +    if S[-k] == "0": +        continue +    tmp = S[:-k] + "0" + "1" * (k - 1) +    X.append(int(tmp, 2)) -for k in Kl: +for n in X: -        if issubset(A[i], k): +        if A[i] & n == A[i]: -    ans = max(tmp, ans) +    ans = max(ans, tmp)