N,K,*X = list(map(int, open(0).read().split()))

S = bin(K)[2:]

L = len(S)

one = set()

ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]

kls = [K]

ans = 0

for i in range(L):

  if S[i]=='1':

    m = int(S[:i]+'0'+'1'*(L-i-1),2)

    kls.append(m)

for k in kls:

  m = 0

  for a,b in ls:

    if k==k|a:

      m += b

  ans = max(ans,m)

print(ans)
N,K,*X = list(map(int,open(0).read().split()))

S = bin(K)[2:]

L = len(S)

ls = [(a,b) for a,b in zip(*[iter(X)]*2)]

s = '0'

ans = 0

for i,c in enumerate(S):

  if c=='0':

    s += c

    continue

  j = L-i

  m = (1<<(j-1))-1

  n = int(s,2)<<j

  x = m|n

  v = 0

  for a,b in ls:

    if x==x|a:

      v += b

  ans = max(v,ans)

  s += c

v = 0

for a,b in ls:

  if K==K|a:

    v += b

ans = max(ans,v)

print(ans)

N, K, *X = list(map(int, open(0).read().split()))
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a, b) for a, b in zip(*[iter(X)] * 2) if a <= K]
kls = [K]
ans = 0
for i in range(L):
    if S[i] == "1":
        m = int(S[:i] + "0" + "1" * (L - i - 1), 2)
        kls.append(m)
for k in kls:
    m = 0
    for a, b in ls:
        if k == k | a:
            m += b
    ans = max(ans, m)
print(ans)

N, K, *X = list(map(int, open(0).read().split()))
S = bin(K)[2:]
L = len(S)
ls = [(a, b) for a, b in zip(*[iter(X)] * 2)]
s = "0"
ans = 0
for i, c in enumerate(S):
    if c == "0":
        s += c
        continue
    j = L - i
    m = (1 << (j - 1)) - 1
    n = int(s, 2) << j
    x = m | n
    v = 0
    for a, b in ls:
        if x == x | a:
            v += b
    ans = max(v, ans)
    s += c
v = 0
for a, b in ls:
    if K == K | a:
        v += b
ans = max(ans, v)
print(ans)

-one = set() -ls = [(a, b) for a, b in zip(*[iter(X)] * 2) if a <= K] -kls = [K] +ls = [(a, b) for a, b in zip(*[iter(X)] * 2)] +s = "0" -for i in range(L): -    if S[i] == "1": -        m = int(S[:i] + "0" + "1" * (L - i - 1), 2) -        kls.append(m) -for k in kls: -    m = 0 +for i, c in enumerate(S): +    if c == "0": +        s += c +        continue +    j = L - i +    m = (1 << (j - 1)) - 1 +    n = int(s, 2) << j +    x = m | n +    v = 0 -        if k == k | a: -            m += b -    ans = max(ans, m) +        if x == x | a: +            v += b +    ans = max(v, ans) +    s += c +v = 0 +for a, b in ls: +    if K == K | a: +        v += b +ans = max(ans, v)