a = int(input())
b = int(input())
la = -1
lb = -1
while la != a and lb != b:
	a1 = a^b
	b1 = (a&b)<<1
	la = a
	lb = b
	a = a1
	b = b1
print(b)