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

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



# そのままの　ｋ

ans = 0

for a, b in ab:

    if k & a == a:

        ans += b



for i in range(31):

    # 上からi桁目までいっち、あとは1111

    if k >> i & 1 == 0:

        continue

    nk = k

    nk &= ~(1 << i)

    for j in range(i - 1, -1, -1):

        nk |= 1 << j



    cnt = 0

    for j in range(n):

        a, b = ab[j]

        if (a & nk) == a:

            cnt += b

    ans = max(ans, cnt)

print(ans)

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

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



ans = sum([b for a, b in ab if k & a == a])



for i in range(30):

    if k >> i & 1:

        nk = 1 << i ^ k

        for j in range(i):

            nk |= 1 << j

        ans = max(ans, sum([b for a, b in ab if nk & a == a]))

print(ans)

n, k = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
# そのままの　ｋ
ans = 0
for a, b in ab:
    if k & a == a:
        ans += b
for i in range(31):
    # 上からi桁目までいっち、あとは1111
    if k >> i & 1 == 0:
        continue
    nk = k
    nk &= ~(1 << i)
    for j in range(i - 1, -1, -1):
        nk |= 1 << j
    cnt = 0
    for j in range(n):
        a, b = ab[j]
        if (a & nk) == a:
            cnt += b
    ans = max(ans, cnt)
print(ans)

n, k = list(map(int, input().split()))
ab = [tuple(map(int, input().split())) for _ in range(n)]
ans = sum([b for a, b in ab if k & a == a])
for i in range(30):
    if k >> i & 1:
        nk = 1 << i ^ k
        for j in range(i):
            nk |= 1 << j
        ans = max(ans, sum([b for a, b in ab if nk & a == a]))
print(ans)

-# そのままの　ｋ -ans = 0 -for a, b in ab: -    if k & a == a: -        ans += b -for i in range(31): -    # 上からi桁目までいっち、あとは1111 -    if k >> i & 1 == 0: -        continue -    nk = k -    nk &= ~(1 << i) -    for j in range(i - 1, -1, -1): -        nk |= 1 << j -    cnt = 0 -    for j in range(n): -        a, b = ab[j] -        if (a & nk) == a: -            cnt += b -    ans = max(ans, cnt) +ans = sum([b for a, b in ab if k & a == a]) +for i in range(30): +    if k >> i & 1: +        nk = 1 << i ^ k +        for j in range(i): +            nk |= 1 << j +        ans = max(ans, sum([b for a, b in ab if nk & a == a]))