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

l = [tuple(map(int, input().split())) for _ in range(N)]

cds = [K]

b = 0

for i in range(30)[::-1]:

    if K&(1<<i):

        cds.append(b + (1<<i) - 1)

        b += (1<<i)



ans = 0

for k in cds:

    buf = 0

    for i, j in l:

        if i|k==k:

            buf += j

    ans = max(ans, buf)

print(ans)

import sys

input=sys.stdin.readline





def solve():

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

    l = [tuple(map(int, input().split())) for _ in range(N)]

    candidates = [K]

    b = 0

    for i in range(30)[::-1]:

        if K&(1<<i):

            candidates.append(b + (1<<i) - 1)

            b += (1<<i)



    ans = 0

    for k in candidates:

        buf = 0

        for i, j in l:

            if i|k==k:

                buf += j

        ans = max(ans, buf)

    print(ans)





if __name__ == "__main__":

    solve()

N, K = list(map(int, input().split()))
l = [tuple(map(int, input().split())) for _ in range(N)]
cds = [K]
b = 0
for i in range(30)[::-1]:
    if K & (1 << i):
        cds.append(b + (1 << i) - 1)
        b += 1 << i
ans = 0
for k in cds:
    buf = 0
    for i, j in l:
        if i | k == k:
            buf += j
    ans = max(ans, buf)
print(ans)

import sys

input = sys.stdin.readline


def solve():
    N, K = list(map(int, input().split()))
    l = [tuple(map(int, input().split())) for _ in range(N)]
    candidates = [K]
    b = 0
    for i in range(30)[::-1]:
        if K & (1 << i):
            candidates.append(b + (1 << i) - 1)
            b += 1 << i
    ans = 0
    for k in candidates:
        buf = 0
        for i, j in l:
            if i | k == k:
                buf += j
        ans = max(ans, buf)
    print(ans)


if __name__ == "__main__":
    solve()

-N, K = list(map(int, input().split())) -l = [tuple(map(int, input().split())) for _ in range(N)] -cds = [K] -b = 0 -for i in range(30)[::-1]: -    if K & (1 << i): -        cds.append(b + (1 << i) - 1) -        b += 1 << i -ans = 0 -for k in cds: -    buf = 0 -    for i, j in l: -        if i | k == k: -            buf += j -    ans = max(ans, buf) -print(ans) +import sys + +input = sys.stdin.readline + + +def solve(): +    N, K = list(map(int, input().split())) +    l = [tuple(map(int, input().split())) for _ in range(N)] +    candidates = [K] +    b = 0 +    for i in range(30)[::-1]: +        if K & (1 << i): +            candidates.append(b + (1 << i) - 1) +            b += 1 << i +    ans = 0 +    for k in candidates: +        buf = 0 +        for i, j in l: +            if i | k == k: +                buf += j +        ans = max(ans, buf) +    print(ans) + + +if __name__ == "__main__": +    solve()