N = int(input())
#* spagetti
for i in range(N):
Max = [ 2**i for i in range()]
def ListToInt(InputList):
ReturnValue = 0
for i, value in enumerate(InputList):
if value == 1:
ReturnValue += 2**(len(InputList)-i-1)
return ReturnValue
RangeTop = int(input())
b = len(bin(RangeTop)[2:])
OsszeszamlaloLista = [0 for i in range(b)]
osszeg = 0
for i in range(RangeTop+1):
osszeg ^= i
for index, j in enumerate(str(bin(i)[2:]).zfill(b)):
if j == "1":
OsszeszamlaloLista[index] += 1
KeresettSzamBinarisban = [0 for i in range(b)]
for i, value in enumerate(OsszeszamlaloLista):
if int(value) % 2 == 0 and value != 0:
KeresettSzamBinarisban[i] = 1
if ListToInt(KeresettSzamBinarisban) > RangeTop:
KeresettSzamBinarisban[i] = 0
print(osszeg, osszeg^ListToInt(KeresettSzamBinarisban))
#! x = 1
#! Max = [ x += x for i in range(b)]