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

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



ans = sum(b for a, b in ab if a | k == k)

k_bin = bin(k)

# print(k_bin)

for i in range(len(k_bin) - 2):

    if (k >> i) & 1:

        x = k_bin[:-(i + 1)] + '0' + '1' * i

        x = int(x, 0)



        cand = 0

        for a, b in ab:

            if a | x == x:

                cand += b

        # print(i, bin(x), cand)

        ans = max(ans, cand)



print(ans)

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

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



k_subset = [k]

for i in range(len(bin(k)) - 2):

    if (k >> i) & 1:

        x = k & ~(1 << i)  # remove i-th bit

        x = x | ((1 << i) - 1)  # add 1 to j-th bit (j<i)

        k_subset.append(x)



ans = max(sum(b for a, b in ab if a | x == x) for x in k_subset)



print(ans)

n, k = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
ans = sum(b for a, b in ab if a | k == k)
k_bin = bin(k)
# print(k_bin)
for i in range(len(k_bin) - 2):
    if (k >> i) & 1:
        x = k_bin[: -(i + 1)] + "0" + "1" * i
        x = int(x, 0)
        cand = 0
        for a, b in ab:
            if a | x == x:
                cand += b
        # print(i, bin(x), cand)
        ans = max(ans, cand)
print(ans)

n, k = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
k_subset = [k]
for i in range(len(bin(k)) - 2):
    if (k >> i) & 1:
        x = k & ~(1 << i)  # remove i-th bit
        x = x | ((1 << i) - 1)  # add 1 to j-th bit (j<i)
        k_subset.append(x)
ans = max(sum(b for a, b in ab if a | x == x) for x in k_subset)
print(ans)

-ans = sum(b for a, b in ab if a | k == k) -k_bin = bin(k) -# print(k_bin) -for i in range(len(k_bin) - 2): +k_subset = [k] +for i in range(len(bin(k)) - 2): -        x = k_bin[: -(i + 1)] + "0" + "1" * i -        x = int(x, 0) -        cand = 0 -        for a, b in ab: -            if a | x == x: -                cand += b -        # print(i, bin(x), cand) -        ans = max(ans, cand) +        x = k & ~(1 << i)  # remove i-th bit +        x = x | ((1 << i) - 1)  # add 1 to j-th bit (j<i) +        k_subset.append(x) +ans = max(sum(b for a, b in ab if a | x == x) for x in k_subset)