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

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

bk=list(bin(k)[2:])

if '0' not in bk:

  t=k

  ans=0

  for a,b in ab:

    if a<=t:ans+=b

  print(ans)

else:

  ks=[k]

  for i in range(len(bk)):

    if bk[i]=='1':

      if i==0:

        ks.append(int('1'*(len(bk)-1),2))

      else:

        ks.append(int(''.join(bk[:i])+'0'+'1'*(len(bk)-i-1),2))

  ans=[0]*len(ks)

  for a,b in ab:

    for i in range(len(ks)):

      if a&ks[i]==a:ans[i]+=b

  print((max(ans)))
def main(n,k,ab):

  ks=[k]

  m=len(bin(k))-2

  # kはm桁

  kbin=bin(k)[2:]

  now=0

  for i in range(m):

    if kbin[i]=='1' and i<m-1:

      ks.append(now+pow(2,m-i-1)-1)

    now+=int(kbin[i])*pow(2,m-i-1)

  ans=0

  for x in ks:

    tmp=0

    for a,b in ab:

      if a|x==x:tmp+=b

    ans=max(ans,tmp)

  print(ans)



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

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

main(n,k,ab)
n, k = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
bk = list(bin(k)[2:])
if "0" not in bk:
    t = k
    ans = 0
    for a, b in ab:
        if a <= t:
            ans += b
    print(ans)
else:
    ks = [k]
    for i in range(len(bk)):
        if bk[i] == "1":
            if i == 0:
                ks.append(int("1" * (len(bk) - 1), 2))
            else:
                ks.append(int("".join(bk[:i]) + "0" + "1" * (len(bk) - i - 1), 2))
    ans = [0] * len(ks)
    for a, b in ab:
        for i in range(len(ks)):
            if a & ks[i] == a:
                ans[i] += b
    print((max(ans)))

def main(n, k, ab):
    ks = [k]
    m = len(bin(k)) - 2
    # kはm桁
    kbin = bin(k)[2:]
    now = 0
    for i in range(m):
        if kbin[i] == "1" and i < m - 1:
            ks.append(now + pow(2, m - i - 1) - 1)
        now += int(kbin[i]) * pow(2, m - i - 1)
    ans = 0
    for x in ks:
        tmp = 0
        for a, b in ab:
            if a | x == x:
                tmp += b
        ans = max(ans, tmp)
    print(ans)


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

+def main(n, k, ab): +    ks = [k] +    m = len(bin(k)) - 2 +    # kはm桁 +    kbin = bin(k)[2:] +    now = 0 +    for i in range(m): +        if kbin[i] == "1" and i < m - 1: +            ks.append(now + pow(2, m - i - 1) - 1) +        now += int(kbin[i]) * pow(2, m - i - 1) +    ans = 0 +    for x in ks: +        tmp = 0 +        for a, b in ab: +            if a | x == x: +                tmp += b +        ans = max(ans, tmp) +    print(ans) + + -bk = list(bin(k)[2:]) -if "0" not in bk: -    t = k -    ans = 0 -    for a, b in ab: -        if a <= t: -            ans += b -    print(ans) -else: -    ks = [k] -    for i in range(len(bk)): -        if bk[i] == "1": -            if i == 0: -                ks.append(int("1" * (len(bk) - 1), 2)) -            else: -                ks.append(int("".join(bk[:i]) + "0" + "1" * (len(bk) - i - 1), 2)) -    ans = [0] * len(ks) -    for a, b in ab: -        for i in range(len(ks)): -            if a & ks[i] == a: -                ans[i] += b -    print((max(ans))) +main(n, k, ab)