A little girl loves problems on bitwise operations very much. Here's one of them.

You are given two integers l and r. Let's consider the values of $a \oplus b$ for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value among all considered ones.

Expression $x \oplus y$ means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal — as «xor».


-----Input-----

The single line contains space-separated integers l and r (1 ≤ l ≤ r ≤ 10^18).

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.


-----Output-----

In a single line print a single integer — the maximum value of $a \oplus b$ for all pairs of integers a, b (l ≤ a ≤ b ≤ r).


-----Examples-----
Input
1 2

Output
3

Input
8 16

Output
31

Input
1 1

Output
0

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Implementation

Greedy algorithms

Dynamic programming

Mathematics


Solutions:
import math

def maxor(bawah, atas):
	if bawah == atas:
		return 0
	xor = bawah ^ atas
	pangkat2 = math.log(xor, 2)
	return 2 ** int(math.floor(pangkat2) + 1) - 1
a = input().split()
print(maxor(int(a[0]), int(a[1])))


(a, b) = map(int, input().split())
b1 = bin(b)[2:]
a1 = bin(a)[2:]
if len(a1) == len(b1):
	d = b ^ a
	v = d.bit_length()
	print(int('0' + '1' * v, 2))
else:
	print(int('1' * len(b1), 2))


(a, b) = map(int, input().split())
k = 2 ** (a ^ b).bit_length() - 1
print(k)


import math

def Maxxor(l, r):
	if l == r:
		return 0
	else:
		reflog = math.floor(math.log2(r))
		ref = 2 ** reflog
		if l < ref:
			return 2 * ref - 1
		else:
			return Maxxor(l - ref, r - ref)
(l, r) = map(int, input().split())
ans = Maxxor(l, r)
print(ans)


(l, r) = map(int, input().split())
print(2 ** (l ^ r).bit_length() - 1)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	(l, r) = map(int, input().split())
	for i in range(62, -1, -1):
		if 1 << i & l ^ 1 << i & r:
			print((1 << i + 1) - 1)
			break
	else:
		print(0)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


import sys
(l, r) = map(int, sys.stdin.readline().split())
binr = list(str(bin(r)))[2:]
binl = list(str(bin(l)))[2:]
lenr = len(binr)
lenl = len(binl)
for i in range(lenr - lenl):
	binl.insert(0, 0)
ans = ['1']
length = lenr
status = 0
for i in range(0, length):
	if status == 1:
		ans.append('1')
	if binr[i] != binl[i]:
		status = 1
if status == 0:
	print(0)
else:
	strans = ''.join(ans)
	print(int(strans, 2))


from sys import stdin

def maxXORInRange(L, R):
	LXR = L ^ R
	msbPos = 0
	while LXR:
		msbPos += 1
		LXR >>= 1
	(maxXOR, two) = (0, 1)
	while msbPos:
		maxXOR += two
		two <<= 1
		msbPos -= 1
	return maxXOR
(L, R) = list(map(int, stdin.readline().split()))
print(maxXORInRange(L, R))


(l, r) = map(int, input().split())

def findbits(n):
	bits = [None] * 66
	i = 0
	for i in range(66):
		bits[i] = n & 1
		n >>= 1
	return bits
bitsa = findbits(l)
bitsb = findbits(r)
cnt = 0
for i in range(66):
	if bitsa[i] != bitsb[i]:
		cnt = i + 1
ans = (1 << cnt) - 1
print(ans)


(a, b) = list(map(int, input().split()))
c = 1
result = a ^ b
while c <= result:
	c *= 2
c -= 1
print(c)


a = [int(x) for x in input().split()]
n = a[0] ^ a[1]
x = bin(n)[2:]
f = 0
for i in range(len(x)):
	if x[i] == '1':
		f = 1
		break
l = len(x) - i
sum = 0
for i in range(l):
	sum += 2 ** i
if f == 0:
	sum = 0
print(sum)


def maxXORInRange(L, R):
	LXR = L ^ R
	msbPos = 0
	while LXR:
		msbPos += 1
		LXR >>= 1
	(maxXOR, two) = (0, 1)
	while msbPos:
		maxXOR += two
		two <<= 1
		msbPos -= 1
	return maxXOR
(L, R) = [int(i) for i in input().split()]
print(maxXORInRange(L, R))


from sys import stdin as si

class Solution:

	def bazinga(self, a, b):
		if a == b:
			return 0
		z = lambda x: list(bin(x))[2:]
		ii = lambda x: int(''.join(x), 2)
		(a, b) = (z(a), z(b))
		a = ['0'] * (len(b) - len(a)) + a
		i = len(b) - 1
		while i > 0:
			if a[i] == b[i]:
				if a[i] == '0':
					a[i] = '1'
					if ii(a) >= ii(b):
						a[i] = '0'
						break
				else:
					b[i] = '0'
					if ii(a) >= ii(b):
						b[i] = '1'
						break
			i -= 1
		return ii(a) ^ ii(b)
(n, m) = map(int, si.readline().strip().split())
S = Solution()
print(S.bazinga(n, m))


(l, r) = map(int, input().split())
ans = 0
(a, b, c) = ([], [], [])
if l == r:
	print(0)
	exit()
for i in range(63, -1, -1):
	if (r ^ l) & 1 << i:
		for j in range(i, -1, -1):
			ans |= 1 << j
		break
print(ans)


l = [int(x) for x in input().split()]
l.sort()
(b, a) = l
s1 = list(bin(a)[2:])
s2 = list(bin(b)[2:])
if s1 == s2:
	print(0)
elif len(s1) == len(s2):
	cont = 0
	while s1[cont] == s2[cont]:
		s1[cont] = '0'
		cont += 1
	for i in range(cont, len(s1)):
		s1[i] = '1'
	print(int(''.join(s1), 2))
else:
	for i in range(len(s1)):
		s1[i] = '1'
	print(int(''.join(s1), 2))


def maxXORInRange(L, R):
	LXR = L ^ R
	msbPos = 0
	while LXR:
		msbPos += 1
		LXR >>= 1
	maxXOR = (1 << msbPos) - 1
	return maxXOR
(l, r) = map(int, input().split())
print(maxXORInRange(l, r))


def solve():
	(l, r) = map(int, input().split())
	if l == r:
		print(0)
		return
	mx = str(bin(l ^ r))
	x = len(mx[2:])
	print(2 ** x - 1)
solve()


(l, r) = [int(i) for i in input().split(' ')]
for i in range(70, -1, -1):
	if l & 1 << i == r & 1 << i:
		continue
	else:
		print((1 << i + 1) - 1)
		break
else:
	print(0)


(l, r) = list(map(int, input().split()))
i = 0
if l == r:
	if l == 1 and r == 1:
		print(0)
	else:
		print(1)
else:
	(l, r) = (format(l, 'b'), format(r, 'b'))
	if len(l) == len(r):
		while l[i] == r[i]:
			i += 1
	print((1 << len(r) - i) - 1)


(l, r) = [int(x) for x in input().split()]

def solve(l, r):
	if l == r:
		return 0
	bits_l = '{0:b}'.format(l)
	bits_r = '{0:b}'.format(r)
	bits_l = '0' * (len(bits_r) - len(bits_l)) + bits_l
	p = len(bits_l) - next((i for i in range(len(bits_l)) if bits_l[i] != bits_r[i])) - 1
	return 2 ** (p + 1) - 1
print(solve(l, r))


(l, r) = map(int, input().split())
if l == r:
	print(0)
	exit()
x = 1
while x <= r:
	x = x << 1
x = x >> 1
k = x
while x <= l or x > r:
	if x <= l:
		x += k
	else:
		x -= k
	k = k >> 1
print(x ^ x - 1)


def bina(bi):
	binary1 = bi
	(decimal, i, n) = (0, 0, 0)
	while bi != 0:
		dec = bi % 10
		decimal = decimal + dec * pow(2, i)
		bi = bi // 10
		i += 1
	return decimal

def con(n):
	return bin(n).replace('0b', '')
(l, r) = map(int, input().split())
k = con(l)
m = con(r)
k = list(str(k))
m = list(str(m))
j = len(m) - len(k)
k = ['0'] * j + k
c = 0
for i in range(len(m)):
	if k[i] != m[i]:
		c = 1
	if k[i] == m[i] and k[i] == '1' and (c == 1):
		k[i] = '0'
	elif k[i] == m[i] and k[i] == '0' and (c == 1):
		k[i] = '1'
k = int(''.join(k))
m = int(''.join(m))
print(bina(k) ^ bina(m))


from operator import xor
r = list(map(int, input().split()))
ms = xor(r[0], r[1])
max = 0
sum = 1
while ms > 0:
	ms >>= 1
	max += sum
	sum <<= 1
print(max)


def solve(a: int, b: int) -> int:
	if a > b:
		(a, b) = (b, a)
	ba = bin(a)[2:]
	bb = bin(b)[2:]
	r = ''
	if len(ba) != len(bb):
		int('1' * len(bb), 2)
	else:
		for (ca, cb) in zip(ba, bb):
			if ca == cb:
				r += '0'
			else:
				r += '1'
				break
	r += '1' * (len(bb) - len(r))
	return int(r, 2)
(a, b) = map(int, input().split())
print(solve(a, b))


lr = input().split()
(l, r) = [int(x) for x in lr]
if l == r:
	print(0)
else:
	(a, b) = (list(bin(l)[2:]), list(bin(r)[2:]))
	if len(a) == len(b):
		i = 0
		while a[i] == b[i]:
			i += 1
		left = '1' * (len(a) - i)
		print(int(left, 2))
	elif len(a) > len(b):
		left = '1' * len(a)
		print(int(left, 2))
	else:
		left = '1' * len(b)
		print(int(left, 2))


(l, r) = map(int, input().split())
if l == r:
	print(0)
	exit()
(binr, binl) = (bin(r)[2:], bin(l)[2:])
binl = '0' * (len(binr) - len(binl)) + binl
for i in range(len(binl)):
	if binl[i] != binr[i]:
		binl = '1' * len(binl[i:])
		break
print(int(binl, 2))


(A, B) = map(int, input().split())
print((1 << (A ^ B).bit_length()) - 1)


string = input()
(l, r) = string.split()
l = int(l)
r = int(r)
p = l ^ r
x = 1
while x <= p:
	x = x << 1
print(x - 1)


(l, r) = map(int, input().split())
i = 61
mx = 0
while i >= 0:
	if l & 1 << i ^ r & 1 << i:
		break
	i -= 1
while i >= 0:
	mx ^= 1 << i
	i -= 1
print(mx)


(a, b) = map(int, input().split())
if a == b:
	print(0)
else:
	x = a ^ b
	c = 0
	while x:
		x //= 2
		c += 1
	print(2 ** c - 1)


def number(pos):
	ans = 0
	for i in range(pos + 1):
		ans += 2 ** i
	return ans
(l, r) = input().split()
l = int(l)
r = int(r)
if l == r:
	print(0)
else:
	b_pos = 0
	i = 0
	while l > 0 or r > 0:
		if l % 2 != r % 2:
			b_pos = i
		l >>= 1
		r >>= 1
		i += 1
	print(number(b_pos))


(l, r) = [int(x) for x in input().split()]
q = l ^ r
a = 1
while q:
	q //= 2
	a <<= 1
print(a - 1)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(l, r) = I()
if l - r == 0:
	print(0)
else:
	ans = []
	a = list(format(l, '064b'))
	b = list(format(r, '064b'))
	i = 0
	ll = l
	rr = r
	while a[i] == b[i]:
		i += 1
	for i in range(i, 64):
		if a[i] == '0' and b[i] == '0':
			k = l ^ 2 ** (64 - i - 1)
			if k <= rr:
				l = k
				a[i] = '1'
		elif a[i] == '1' and b[i] == '1':
			k = r - 2 ** (64 - i - 1)
			if k >= ll:
				b[i] = '0'
				r = k
	print(l ^ r)


def main():
	(l, r) = map(int, input().split())
	if l == r:
		print(0)
		return
	l = bin(l)[2:]
	r = bin(r)[2:]
	if len(l) == len(r):
		i = 1
		while l[i] == r[i]:
			i += 1
		tam = len(l) - i
	else:
		tam = len(r)
	num = ''
	for i in range(tam):
		num += '1'
	print(int(num, 2))
main()


def bin(a):
	if a <= 1:
		return a
	else:
		return 10 * bin(a // 2) + a % 2

def convBin(a):
	(k, i) = (0, 0)
	while a != 0:
		k += a % 10 * int(2 ** i)
		a //= 10
		i += 1
	return k

def maxi(a, b):
	if a == b:
		return 0
	elif a + 1 == b:
		return a ^ b
	elif a + 2 == b:
		x = a ^ a + 1
		y = a ^ a + 2
		z = a + 1 ^ a + 2
		return max(max(x, y), z)
	else:
		x = str(bin(a ^ b))
		y = '1' * len(x)
		return convBin(int(y))
a = list(map(int, input().split()))
print(maxi(a[0], a[1]))


l = input().split()
a = int(l[0])
b = int(l[1])
e = max(a, b)
r = min(a, b)
d = format(e, 'b')
c = 0
t = 0
j = 0
x = 0
if a != b:
	for i in range(len(d), 0 + j, -1):
		c += 2 ** (i - 1)
	k = c
	while c ^ r < r or c ^ e > e:
		c = 0
		for i in range(len(d) - j, 0, -1):
			c += 2 ** (i - 1)
		j += 1
else:
	c = 0
print(c)


def main():
	(a, b) = map(int, input().split())
	K = 60
	if a == b:
		ans = 0
	else:
		curr = K
		while b & 1 << curr == a & 1 << curr:
			curr -= 1
		ans = 1 << curr
		curr -= 1
		lb = False
		ga = False
		for i in range(curr, -1, -1):
			if b & 1 << i == 0 and a & 1 << i == 0:
				if not lb:
					ans += 1 << i
					ga = True
				else:
					ans += 1 << i
			elif b & 1 << i == 0 and a & 1 << i == 1:
				ans += 1 << i
			elif b & 1 << i == 1 and a & 1 << i == 0:
				if not lb:
					ans += 1 << i
					ga = True
					lb = True
				else:
					ans += 1 << i
			elif not lb:
				ans += 1 << i
				lb = True
			else:
				ans += 1 << i
	print(ans)
main()


(a, b) = map(int, input().split(' '))
(a, b) = (min(a, b), max(a, b))
bina = str(bin(a))[2:]
binb = str(bin(b))[2:]
lena = len(bina)
lenb = len(binb)
ans = 0
if lena != lenb:
	ans = 2 ** lenb - 1
else:
	a = '0' * (lena - lenb) + bina
	for i in range(lenb):
		if bool(int(bina[i])) != bool(int(binb[i])):
			ans = 2 ** (lenb - i) - 1
			break
print(ans)


(l, r) = list(map(int, input().split()))
res = 0
for it in range(62, -1, -1):
	if l >> it & 1 != r >> it & 1:
		res = (1 << it + 1) - 1
		break
print(res)


entrada = input().split()
l = int(entrada[0])
r = int(entrada[1])
pop = l ^ r
result = 1
while result <= pop:
	result = result << 1
print(result - 1)


(l, r) = map(int, input().split())
a = bin(l)
b = bin(r)
a = '0' * (len(b) - len(a)) + a[2:len(a)]
b = b[2:len(b)]
c = [0 for i in range(len(a))]
flag = False
for i in range(len(a)):
	if a[i] != b[i]:
		flag = True
	if flag:
		c[i] = 1
ans = 0
for j in range(len(a)):
	ans += c[len(a) - 1 - j] * 2 ** j
print(ans)


[l, r] = map(int, input().split())
if l == r:
	print(0)
else:
	found = False
	bin1 = bin(l)[2:]
	bin2 = bin(r)[2:]
	bit = 0
	while len(bin1) < len(bin2):
		bin1 = '0' + bin1
	while len(bin2) < len(bin1):
		bin2 = '0' + bin2
	while found == False:
		if bin1[bit] == bin2[bit]:
			bit += 1
		else:
			found = True
			print((1 << len(bin1) - bit) - 1)


import math
(l, r) = map(int, input().split())
if l == r:
	print('0')
else:
	msb = int(math.log2(r))
	for i in range(msb, -1, -1):
		if l & 1 << i != r & 1 << i:
			break
	print(2 * (1 << i) - 1)


vals = list(map(int, input().split()))
l = vals[0]
r = vals[1]
if l == r:
	print('0')
else:
	i = 0
	j = 0
	while l > 0 or r > 0:
		i += 1
		if l & 1 ^ r & 1 == 1:
			j = i
		l = l >> 1
		r = r >> 1
	ans = 1
	for i in range(0, j):
		ans = ans * 2
	ans -= 1
	print(ans)


(l, r) = map(int, input().split())
ls = str(bin(l))[2:]
rs = str(bin(r))[2:]
llog = len(ls)
rlog = len(rs)
ans = 0
if llog < rlog:
	z = rlog - 1
	while z > -1:
		ans += 2 ** z
		z -= 1
else:
	ct = 0
	stringa = ''
	for i in range(len(ls)):
		if ls[i] == rs[i] and ct == 0:
			stringa += ls[i]
		if ls[i] == '0' and rs[i] == '1':
			ct += 1
			stringa += ls[i]
		if ls[i] == '1' and rs[i] == '0':
			stringa += ls[i]
		if ls[i] == rs[i] and ct > 0:
			stringa += str((int(rs[i]) + 1) % 2)
	ans = int(stringa, 2) ^ r
print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(l, r) = list(map(int, input().split()))
if l == r:
	print(0)
else:
	a = bin(l)[2:]
	b = bin(r)[2:]
	x = len(a)
	y = len(b)
	if x != y:
		ans = 0
		for i in range(y):
			ans += 2 ** i
		print(ans)
	else:
		for i in range(x):
			if a[i] != b[i]:
				ind = i
				break
		l = x - ind
		ans = 0
		for i in range(l):
			ans += 2 ** i
		print(ans)


import bisect
import sys
input = sys.stdin.readline
import collections
import heapq
t = 1
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	(ans, a, b) = (0, 0, 0)
	mul = 2 ** 60
	for i in range(60, -1, -1):
		(ch1, ch2) = (0, 0)
		if a + mul <= l:
			a += mul
			ch1 = 1
		if b + mul <= l:
			b += mul
			ch2 = 1
		if ch1 ^ ch2 == 1:
			ans += mul
		elif ch1 == 0 and ch2 == 0:
			if a + mul <= r:
				a += mul
				ans += mul
			elif b + mul <= r:
				b += mul
				ans += mul
		mul //= 2
	return ans
for _ in range(t):
	(l, r) = map(int, input().split())
	print(solve())


(l, r) = map(int, input().split())
if l == r:
	print(0)
elif r & r - 1 == 0:
	print(r ^ r - 1)
else:
	x = l ^ r
	p1 = 1
	while p1 <= x:
		p1 *= 2
	print(p1 - 1)


from math import *
(l, r) = list(map(int, input().split(' ')))
print((2 << floor(log2(l ^ r))) - 1 if l != r else 0)


[l, r] = list(map(int, input().split()))
if l == r:
	print(0)
else:
	a = bin(l)
	b = bin(r)
	a = list(a[2:])
	b = list(b[2:])
	d = 0
	if len(a) != len(b):
		d = len(b) - len(a)
		acta = ['0'] * d
		for j in a:
			acta.append(j)
		a = acta
	flag = 0
	sol = len(b)
	pos = -1
	for i in range(len(b) - 1, -1, -1):
		if a[i] != b[i]:
			pos = sol - i
	if pos != -1:
		sol = pos
	print(2 ** sol - 1)


(n, m) = map(int, input().split())
n = str(bin(n))[2:]
m = str(bin(m))[2:]
n = '0' * (len(m) - len(n)) + n
f = 0
for i in range(len(n)):
	if n[i] == '0' and m[i] == '1':
		print(2 ** (len(n) - i) - 1)
		f = 1
		break
if not f:
	print(f)


(l, r) = map(int, input().split())
(target, final) = (l ^ r, 1)
while target:
	target >>= 1
	final <<= 1
print(final - 1)


(l, r) = [int(i) for i in input().split()]
bitafter = -1
for i in range(60, -1, -1):
	if l & 1 << i != r & 1 << i:
		bitafter = i
		break
res = 0
while bitafter >= 0:
	res += 1 << bitafter
	bitafter -= 1
print(res)


(a, b) = input().split()
a = int(a)
b = int(b)
s = a ^ b
cnt = 0
while s != 0:
	s = int(s / 2)
	cnt = cnt + 1
print(2 ** cnt - 1)


lr = input()
lr_list = lr.split(' ')
l = int(lr_list[0])
r = int(lr_list[1])
xor = l ^ r
bms = 0
while xor != 0:
	bms = bms + 1
	xor = xor >> 1
maxxor = 0
dois = 1
while bms != 0:
	maxxor = maxxor + dois
	dois = dois << 1
	bms = bms - 1
print(maxxor)


(l, r) = list(map(int, input().split()))
p = l ^ r
x = 1
while x <= p:
	x = x << 1
print(x - 1)


(l, r) = map(int, input().split())
al = []
ar = []
while r:
	p = r % 2
	ar.append(p)
	r = r // 2
while l:
	p = l % 2
	al.append(p)
	l = l // 2
if len(ar) != len(al):
	ans = 2 ** len(ar) - 1
else:
	n = len(ar)
	s = 0
	k = 0
	for i in range(n - 1, -1, -1):
		if ar[i] != al[i]:
			k = i + 1
			break
	ans = 2 ** k - 1
	if k == 0:
		ans = 0
print(ans)


import sys
import itertools as it
import math as mt
import collections as cc
I = lambda : list(map(int, input().split()))
(l, r) = I()
ans = 0
for i in range(64, -1, -1):
	temp = 1 << i
	if temp & l != temp & r:
		print(pow(2, i + 1) - 1)
		sys.exit()
print(0)


(l, r) = ['{:061b}'.format(int(x)) for x in input().split()]
pot = 0
for i in range(61):
	if l[i] != r[i]:
		pot = 61 - i
		break
if pot == 0:
	print(0)
else:
	print(2 ** pot - 2 ^ 1)


(a, b) = map(int, input().split())
a = a ^ b
k = 0
while a:
	k += 1
	a = a >> 1
print(2 ** k - 1)


import math
(l, r) = map(int, input().strip().split())
lr = int(math.log(r) / math.log(2))
ll = int(math.log(l) / math.log(2))
if lr > ll:
	lr += 1
	ans = 1 << lr
	ans -= 1
	print(ans)
else:
	ans = 0
	fl = False
	for i in range(lr, -1, -1):
		if l & 1 << i == r & 1 << i and fl == False:
			continue
		elif l & 1 << i != r & 1 << i:
			ans = ans + (1 << i)
			fl = True
		elif fl == True:
			ans = ans + (1 << i)
	print(ans)


(a, b) = input().split()
if a == b:
	print('0')
else:
	xor = bin(int(a) ^ int(b))[2:]
	a = bin(int(a))[2:]
	b = bin(int(b))[2:]
	ans = ''
	if a[0] == b[0]:
		ans += '0'
	else:
		ans += '1'
	for i in range(len(xor)):
		ans += '1'
	print(int(ans, 2))


(start, end) = input().split()
start = int(start)
end = int(end)
maximum = 0
save = end
count = 0
if end ^ start == 0:
	print(0)
else:
	while end ^ start > 0:
		end = end >> 1
		start = start >> 1
		count += 1
	print(2 ** count - 1)


import sys
(l, r) = tuple((int(x) for x in sys.stdin.readline().split()))
l = bin(l)
r = bin(r)
l = l[2:]
r = r[2:]
l = l.zfill(len(r))
i = 0
while l[i] == r[i]:
	if i == len(l) - 1:
		print(0)
		return
	i += 1
i = len(l) - i
print(2 ** i - 1)


(l, r) = map(int, input().split())

def maxXor(low, high):
	highestPower = high.bit_length() - 1
	if high == 1 and low == 0:
		return 1
	if highestPower <= 0:
		return 0
	if low < 2 ** highestPower:
		return 2 ** (highestPower + 1) - 1
	return maxXor(low - 2 ** highestPower, high - 2 ** highestPower)
print(maxXor(l, r))


(l, r) = list(map(int, input().strip().split()))
if l == r:
	print(0)
	exit()
(l, r) = (bin(l)[2:].zfill(64), bin(r)[2:].zfill(64))
i = 0
while i < len(r):
	if l[i] == r[i]:
		i += 1
	else:
		break
rslt = len(r[:i]) * '0' + len(r[i:]) * '1'
print(int(rslt, 2))


(l, r) = map(int, input().split())
for i in range(64, -2, -1):
	if i < 0 or 1 << i & l != 1 << i & r:
		break
print((1 << i + 1) - 1)


(left, right) = [int(x) for x in input().split(' ')]
if left == right:
	print(0)
else:
	x = 1
	while x <= right:
		x *= 2
	x //= 2
	y = x
	while y > 0 and x <= left or x > right:
		if x <= left:
			x += y
		else:
			x -= y
		y //= 2
	print(x ^ x - 1)


def solve():
	(l, r) = map(int, input().split())
	ans = l ^ r
	j = 0
	while 1 << j <= ans:
		ans |= 1 << j
		j += 1
	print(ans)
solve()


(a, b) = list(map(int, input().split()))
x = a ^ b
ans = 1
while x > 0:
	x //= 2
	ans *= 2
print(ans - 1)


(l, r) = map(int, input().split())
ans = l ^ r
x = bin(ans)[1:]
if ans == 0:
	print(0)
else:
	ptr = -1
	po = 0
	while True:
		if x[ptr] == '0':
			ans += 2 ** po
		po += 1
		ptr -= 1
		if ptr == -len(x) - 1:
			break
	print(ans)


import math

def maxXor(l, r):
	if l == r:
		return 0
	xor = l ^ r
	twoPows = math.log(xor, 2)
	return 2 ** int(math.floor(twoPows) + 1) - 1
(l, r) = map(int, input().split())
print(maxXor(l, r))


import sys
from collections import deque
from copy import *
from bisect import *
from math import gcd, ceil, sqrt
from itertools import permutations as prm, product

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = 1
while t > 0:
	t -= 1
	(l, r) = mi()
	if len(bin(l)) < len(bin(r)):
		print(2 ** len(bin(r)[2:]) - 1)
	else:
		p = bin(l)[2:]
		q = bin(r)[2:]
		r = 0
		for i in range(len(q)):
			if p[i] != q[i]:
				r = len(p) - i
				break
		print(2 ** r - 1)


def maxXORInRange(L, R):
	LXR = L ^ R
	msbPos = 0
	while LXR:
		msbPos += 1
		LXR >>= 1
	(maxXOR, two) = (0, 1)
	while msbPos:
		maxXOR += two
		two <<= 1
		msbPos -= 1
	return maxXOR
(L, R) = map(int, input().split())
print(maxXORInRange(L, R))


import sys
SIZE = 105
a = SIZE * [0]
b = SIZE * [0]
lr = input().split()
l = int(lr.pop(0))
r = int(lr.pop(0))
if l == r:
	print(0)
else:
	len1 = 0
	len2 = 0
	while l != 0:
		a[len1] = l % 2
		l = int(l / 2)
		len1 += 1
	while r != 0:
		b[len2] = r % 2
		r = int(r / 2)
		len2 += 1
	tag = 0
	for i in range(max(len1, len2) - 1, 0, -1):
		if b[i] == 1 and a[i] == 0:
			tag = i
			break
	print(pow(2, tag + 1) - 1)


arra = []
arrb = []
arr = []
s = ''
temp = 1
value = ans = n = 0

def fill(myList=[], *args):
	for i in range(n):
		arra.insert(0, 0)

def check():
	for (i, j) in zip(arra, arrb):
		if i == j:
			return 1
		else:
			return 0

def Engine1(num):
	if num > 1:
		Engine1(num // 2)
	arra.append(num % 2)

def Engine2(num):
	if num > 1:
		Engine2(num // 2)
	arrb.append(num % 2)
(a, b) = map(int, input().split())
Engine1(a)
Engine2(b)
n = abs(len(arra) - len(arrb))
if len(arra) > len(arrb):
	fill(arrb)
if len(arra) < len(arrb):
	fill(arra)
for i in range(len(arra)):
	if check() == 0:
		break
	check()
	arra.pop(0)
	arrb.pop(0)
for i in range(len(arra)):
	ans += temp
	temp *= 2
print(ans)


(l, r) = map(int, input().split())
r1 = len(bin(r)) - 3
l1 = len(bin(l)) - 3
ans = 0
while l > 0:
	if l1 == r1:
		r -= 1 << l1
		l -= 1 << l1
	else:
		ans = (1 << r1 + 1) - 1
		break
	z1 = min(l, r)
	z2 = max(l, r)
	(l, r) = (z1, z2)
	r1 = len(bin(r)) - 3
	l1 = len(bin(l)) - 3
if ans == 0:
	if l1 == r1:
		if r == 1:
			print(1)
		else:
			print(0)
	else:
		print((1 << r1 + 1) - 1)
else:
	print(ans)


(l, r) = map(int, input().split())
bl = (r - l).bit_length()
print((((r ^ l) >> bl) + 1 << bl) - 1)


(l, r) = [int(x) for x in input().split()]
r = bin(r)[2:]
l = bin(l)[2:]
r = r[::-1]
l = l[::-1]
if l == r:
	print(0)
else:
	l += '0' * (len(r) - len(l))
	p = -1
	for i in range(len(r)):
		if r[i] != l[i]:
			p = i
	a = '1' * p + '0'
	b = '0' * p + '1'
	print(int(a, 2) ^ int(b, 2))


def main():
	(l, r) = map(int, input().split())
	l1 = bin(l)[2:]
	r1 = bin(r)[2:]
	if len(l1) < 64:
		l1 = '0' * (64 - len(l1)) + l1
	if len(r1) < 64:
		r1 = '0' * (64 - len(r1)) + r1
	ans = 0
	for i in range(64):
		if l1[i] != r1[i]:
			ans = pow(2, 64 - i) - 1
			break
	print(ans)
main()


(a, b) = map(int, input().split())
bina = bin(a)[2:]
binb = bin(b)[2:]
length = len(binb)
length2 = len(bina)
bina = '0' * (length - length2) + bina
for i in range(length):
	if bina[i] == binb[i] and bina[i] == '1':
		z = bina[:i] + '0' + bina[i + 1:]
		z1 = int(z, 2)
		if z1 <= b and z1 >= a:
			bina = z
			continue
		z = binb[:i] + '0' + binb[i + 1:]
		z1 = int(z, 2)
		if z1 <= b and z1 >= a:
			binb = z
			continue
	if bina[i] == binb[i] and bina[i] == '0':
		z = binb[:i] + '1' + binb[i + 1:]
		z1 = int(z, 2)
		if z1 <= b and z1 >= a:
			binb = z
			continue
		z = bina[:i] + '1' + bina[i + 1:]
		z1 = int(z, 2)
		if z1 <= b and z1 >= a:
			bina = z
			continue
n1 = int(bina, 2)
n2 = int(binb, 2)
print(n1 ^ n2)


(l, r) = map(int, input().split())
(hmm, t) = (l ^ r, 2 ** 60)
while hmm ^ t > hmm:
	t //= 2
print(2 * t - 1 if hmm != 0 else 0)


(l, r) = map(int, input().split())
a = bin(r)[2:]
b = '0' * (len(a) - len(bin(l)[2:])) + bin(l)[2:]
ans = 0
for i in range(len(a)):
	if a[i] != b[i]:
		ans = 2 ** (len(a) - i) - 1
		break
print(ans)


(l, r) = map(int, input().split())
lx = l
rx = r
l1 = list(bin(l))[2:]
r1 = list(bin(r))[2:]
l1 = ['0'] * (len(r1) - len(l1)) + l1
n = len(r1)
ans = ['0'] * n
d = [0] * n
f = 0
for i in range(n):
	if l1[i] != r1[i]:
		f = 1
	d[i] = f
for i in range(n):
	if d[i] == 0:
		ans[i] = '0'
	elif l1[i] == '0' and r1[i] == '0':
		if lx + 2 ** (n - i - 1) < rx:
			lx += 2 ** (n - i - 1)
			ans[i] = '1'
			l1[i] = '1'
	elif l1[i] == '1' and r1[i] == '1':
		if rx - 2 ** (n - i - 1) > lx:
			rx -= 2 ** (n - i - 1)
			ans[i] = '1'
			r1[i] = '0'
	else:
		ans[i] = '1'
k = ''.join(ans)
print(int(k, 2))


(l, r) = map(int, input().split())
x = l ^ r
a = 2
if l == r:
	print(0)
else:
	while a <= x:
		a = a * 2
	print(a - 1)


(a, b) = list(map(int, input().split()))
s = -1
for i in range(60, 0, -1):
	if a & 1 << i == 0 and b & 1 << i != 0:
		print((1 << i + 1) - 1)
		break
else:
	print(a ^ b)


(a, b) = list(map(int, input().split()))
s1 = list(map(int, reversed(list(bin(a)[2:]))))
s2 = list(map(int, reversed(list(bin(b)[2:]))))
s1 += [0] * (len(s2) - len(s1))
out = 0
for i in range(len(s1)):
	if s1[i] ^ s2[i]:
		out = i + 1
print(2 ** out - 1)


(l, r) = map(int, input().split())
binR = list(bin(r)[2:])
binL = list(bin(l)[2:].rjust(len(binR), '0'))
(f, XOR) = (False, '')
for (i, j) in zip(binR, binL):
	if i != j:
		if i == '1' and (not f):
			f = True
		XOR += '1'
	if i == j:
		if f:
			XOR += '1'
		else:
			XOR += '0'
print(int(XOR, 2))


from math import ceil, sqrt, log

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def is_square(n):
	return int(sqrt(n)) * int(sqrt(n)) == n

def find_div(n):
	d = []
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			if i * i != n:
				d.append(i)
				d.append(n / i)
			else:
				d.append(i)
	return d

def find_x(n):
	d = find_div(2 * n)
	for div in d:
		x2 = div * (div + 2 * n)
		if is_square(x2):
			return sqrt(x2)
	return -1

def find_base_side(n):
	squares = [x * x for x in range(ceil(sqrt(n)))]
	for i in range(len(squares)):
		for j in range(len(squares)):
			if squares[i] + squares[j] == n * n:
				return squares[i]
	return -1

def str_add(n):
	n = list(n)
	for i in range(1, len(n) + 1):
		if n[-i] == '9':
			n[-i] = '0'
		else:
			n[-i] = int(int(n[-i]) + 1)
			break
	n = str(n)
	return n

def str_sub(n):
	n = list(n)
	for i in range(1, len(n) + 1):
		if n[-i] == '0':
			n[-i] = '9'
		else:
			n[-i] = int(int(n[-i]) - 1)
			break
	n = str(n)
	return n

def find_massive_x(n):
	if n % 2 == 0:
		n2 = str(int(pow(n / 2, 2)))
		x = str_sub(n2)
		y = str_add(n2)
	else:
		n2 = str(int(pow(n, 2) / 2))
		x = str_sub(n2)
		y = str_add(n2)
	x = str(x)
	y = str(y)
	print(x, y)

def find_triples(n):
	if n <= 2:
		print(-1)
		return
	else:
		x = find_massive_x(n)
	print(-1)

def find_max_xor(l, r):
	lxr = l ^ r
	msb_pos = 0
	while lxr > 0:
		msb_pos += 1
		lxr //= 2
	return pow(2, msb_pos) - 1
t = 1
while t:
	t = t - 1
	(l, r) = map(int, input().split())
	print(find_max_xor(l, r))


import math
[l, r] = list(map(int, input().split()))
l = l ^ r
if l:
	l = int(math.log(l, 2))
	l = (1 << l + 1) - 1
	print(l)
else:
	print(0)


from operator import xor
(l, r) = map(int, input().split())
c = bin(xor(l, r))[2:]
if c == '0':
	print(0)
else:
	n = len(c)
	print(2 ** n - 1)


(l, r) = map(int, input().split())
a = str(bin(l))
b = str(bin(r))
count = 0
da = len(a) - 2
db = len(b) - 2
if db > da:
	for i in range(db):
		count += 2 ** i
	print(count)
elif l == r:
	print(0)
elif db == da:
	for i in range(3, db + 2):
		if int(b[i]) == 1 and int(a[i]) == 0:
			db = db + 2 - i
			break
	for i in range(db):
		count += 2 ** i
	print(count)


numeros = [int(i) for i in input().split(' ')]
l = bin(numeros[0])
r = bin(numeros[1])
p = -1
if len(r) == len(l):
	for i in range(len(l)):
		if l[i] != r[i]:
			p = i
			break
	if numeros[0] != numeros[1]:
		saida = 2 ** (len(r) - p) - 1
		print(saida)
	else:
		print(0)
elif numeros[0] != numeros[1]:
	saida = 2 ** (len(r) - 2) - 1
	print(saida)
else:
	print(0)


import sys
input = sys.stdin.readline
from math import *
(l, r) = map(int, input().split())
l = list(bin(l)[2:])
r = list(bin(r)[2:])
l = ['0' for i in range(len(r) - len(l))] + l
s = ''
for i in range(len(r)):
	if l[i] == r[i]:
		s += '0'
	else:
		s += '1' * (len(r) - i)
		break
print(int(s, 2))


def main():
	(l, r) = map(int, input().split())
	if l == r:
		print(0)
	else:
		rs = ''
		while r:
			rs += '1' if r % 2 else '0'
			r //= 2
		for i in range(len(rs), 65):
			rs += '0'
		ls = ''
		while l:
			ls += '1' if l % 2 else '0'
			l //= 2
		for i in range(len(ls), 65):
			ls += '0'
		pos = -1
		for i in range(64, -1, -1):
			if rs[i] == '1' and ls[i] == '0':
				pos = i
				break
		ans = 2 ** (pos + 1) - 1
		print(ans)
main()


import sys
input = sys.stdin.readline
(a, b) = map(int, input().split())
if a == b:
	print(0)
else:
	x = a ^ b
	c = 1
	while x:
		x >>= 1
		c <<= 1
	print(c - 1)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	(L, R) = getInts()
	if L == R:
		return 0
	l = len(bin(L)[2:])
	r = len(bin(R)[2:])
	while l == r:
		L -= pow(2, r - 1)
		R -= pow(2, r - 1)
		l = len(bin(L)[2:])
		r = len(bin(R)[2:])
	return pow(2, r) - 1
print(solve())


(l, r) = map(int, input().split())
ans = 0
for i in range(63, -1, -1):
	if r & 1 << i > 0 and l & 1 << i == 0:
		ans = (1 << i + 1) - 1
		break
print(ans)


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
(L, R) = map(int, input().split())
for i in range(64, -1, -1):
	if L & 1 << i != R & 1 << i:
		print((1 << i + 1) - 1)
		exit(0)
print(0)


(a, b) = map(int, input().split())
print((1 << (a ^ b).bit_length()) - 1)


def main():
	(l, r) = (format(int(s), 'b') for s in input().split())
	le = len(r)
	if len(l) == le:
		for i in range(le):
			if l[i] != r[i]:
				print(int('1' * (le - i), 2))
				break
		else:
			print(0)
	else:
		print(int('1' * le, 2))

def __starting_point():
	main()
__starting_point()


(l, r) = map(int, input().split())
j = bin(l ^ r)
ans = 0
i = 0
while 2 ** i <= r - l:
	ans += 2 ** i
	i += 1
while 2 ** i <= r:
	if j[-i - 1] == 'b':
		break
	if j[-i - 1] != '0':
		ans += 2 ** i
	i += 1
print(ans)


(x, y) = map(int, input().split())
z = x ^ y
ca = 1
while z:
	ca <<= 1
	z >>= 1
print(ca - 1)


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
(l, r) = R()
if l == r:
	print('0')
	exit(0)
cnt = -1
ans = 0
while r > 0:
	cnt += 1
	if l % 2 != r % 2:
		ans = cnt
	l = l >> 1
	r = r >> 1
print((1 << ans + 1) - 1)


(l, r) = map(int, input().split())
print(0 if l == r else 2 ** len(bin(l ^ r)[2:]) - 1)


(l, r) = map(int, input().split())
p = bin(l)
p = p[2:]
q = bin(r)
q = q[2:]
t = len(q)
u = len(p)
p = (t - u) * '0' + p
ans = []
for i in range(len(q)):
	if q[i] == '1' and p[i] == '0':
		ans.append(1)
		break
	elif q[i] == '1' and p[i] == '1':
		ans.append(0)
		continue
	elif q[i] == '0' and p[i] == '1':
		ans.append(1)
		continue
	else:
		ans.append(0)
for j in range(i + 1, len(p)):
	ans.append(1)
total = 0
ans.reverse()
for i in range(len(ans)):
	total += pow(2, i) * ans[i]
print(total)


(l, r) = map(int, input().split())
p = l
lp = -1
while p:
	p = p >> 1
	lp += 1
q = r
rp = -1
while q:
	q = q >> 1
	rp += 1
s = max(lp, rp)
n = 0
while s >= 0:
	if l >> s & 1 != r >> s & 1:
		n |= (r >> s & 1) << s
		break
	s -= 1
s -= 1
while s >= 0:
	n |= 1 << s
	s -= 1
print(n)


(a, b) = map(int, input().split())
if a == b:
	print(0)
	exit()
aa = ''
bb = ''
while a or b:
	aa += str(a % 2)
	bb += str(b % 2)
	a //= 2
	b //= 2
aa = aa[::-1]
bb = bb[::-1]
idx = 0
while aa[idx] == bb[idx]:
	idx += 1
ln = len(aa)
r = 2 ** (ln - idx) - 1
print(r)


(a, b) = map(int, input().split())
c = a ^ b
if c == 0:
	print(0)
else:
	l = len('{:b}'.format(c))
	print((1 << l) - 1)


import math

def xor(l, r):
	p = l ^ r
	c = 0
	while p:
		c += 1
		p >>= 1
	return pow(2, c) - 1
(l, r) = input().split()
l = int(l)
r = int(r)
print(xor(l, r))


(l, r) = map(int, input().split())
x = 64
while x >= 0 and l & 1 << x == r & 1 << x:
	x -= 1
print((1 << x + 1) - 1)


(l, r) = list(map(int, input().split()))
if l == r:
	print(0)
else:
	x = l ^ r
	c = 0
	while x > 0:
		x = x // 2
		c = c + 1
	print(2 ** c - 1)


(l, r) = map(int, input().split())
masks = []
for i in range(64, -1, -1):
	if 1 << i > r:
		continue
	masks.append(1 << i)
	(x, y) = (0, 0)
	for k in masks:
		if x < y:
			x += k
		else:
			y += k
	for j in range(64, -1, -1):
		if x >> j & 1 or y >> j & 1:
			continue
		if x + (1 << j) <= r:
			x += 1 << j
		if y + (1 << j) <= r:
			y += 1 << j
	if min(x, y) < l or max(x, y) > r:
		masks.pop()
print(sum(masks))


(l, r) = map(int, input().split())
i = 1 << 60
while i & l == i & r and i != 0:
	i = i >> 1
ans = i
while i > 0:
	i = i >> 1
	ans += i
print(ans)


from collections import deque
(qa, qb) = (deque(), deque())
(a, b) = map(int, input().split())
while a or b:
	qa.appendleft(a & 1)
	qb.appendleft(b & 1)
	a >>= 1
	b >>= 1
while qa and qa[0] == qb[0]:
	qa.popleft()
	qb.popleft()
if not qa:
	print(0)
else:
	print(int('1' * len(qa), 2))


input_arr = [int(i) for i in input().split()]
(a, b) = input_arr

def dec_to_bin(N):
	res = [0] * 64
	pos = 0
	while N != 0:
		last_bit = N & 1
		res[pos] = last_bit
		pos += 1
		N = N >> 1
	return res

def max_xor(a, b):
	a_bin = dec_to_bin(a)
	b_bin = dec_to_bin(b)
	res = ''
	x = ''
	y = ''
	diff_pt_found = False
	for i in range(len(a_bin) - 1, -1, -1):
		if diff_pt_found == False and a_bin[i] == b_bin[i]:
			x += str(a_bin[i])
			y += str(b_bin[i])
		if diff_pt_found == False and a_bin[i] != b_bin[i]:
			diff_pt_found = True
			x += str(a_bin[i])
			y += str(b_bin[i])
			res += '1'
			continue
		if diff_pt_found == True:
			if a_bin[i] != b_bin[i]:
				res += '1'
				x += str(a_bin[i])
				y += str(b_bin[i])
			elif b_bin[i] == 1:
				res += '1'
				x += str(a_bin[i])
				y += str(0)
			elif a_bin[i] == 0:
				res += '1'
				x += str(1)
				y += str(b_bin[i])
	return (x, y, res)

def bin_to_dec(bin):
	bin = str(bin)
	mul = 1
	res = 0
	for i in range(len(bin) - 1, -1, -1):
		if bin[i] == '1':
			res += mul
		mul = mul * 2
	return res
(x, y, res) = max_xor(a, b)
print(bin_to_dec(res))


(l, r) = (int(x) for x in input().split())
limit = l ^ r
if limit != 0:
	limit = len(bin(limit)) - 2
	maxXor = '1' * limit
	print(int(maxXor, 2))
else:
	print(0)


(a, b) = [int(x) for x in input().split(' ')]
idx = 0
if a == b:
	print(0)
else:
	for i in range(63, -1, -1):
		set1 = a >> i & 1
		set2 = b >> i & 1
		if set1 != set2:
			idx = i
			break
	print((1 << idx + 1) - 1)


import sys
(l, r) = tuple((int(x) for x in sys.stdin.readline().split()))
maximum = -1
cur_pow = 1
while cur_pow <= r:
	if cur_pow - 1 >= l:
		cur_result = cur_pow ^ cur_pow - 1
		maximum = max(maximum, cur_result)
	cur_pow *= 2
if maximum < 0:
	n_ones = len(bin(l))
	(str1, str2) = (bin(l), bin(r))
	index = 0
	while index < len(str1) and index < len(str2) and (str1[index] == str2[index]):
		index += 1
		n_ones -= 1
	if n_ones == 0:
		maximum = 0
	else:
		maximum = int('1' * n_ones, 2)
print(maximum)


from sys import stdin, stdout
from collections import defaultdict, Counter
from bisect import bisect, bisect_left
import math
I = stdin.readline
(l, r) = map(int, I().split())

def f(l, r):
	ans = 0
	f = 0
	s = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			now = i ^ j
			if now > ans:
				ans = now
				f = i
				s = j
	print(ans, r - l, l, r)
	n = len(bin(r)[2:])
	print(l, r, f, s)
	print(bin(l)[2:], bin(r)[2:])
	print(bin(f)[2:], bin(s)[2:])
	print(bin(ans)[2:])
a = bin(l)[2:]
b = bin(r)[2:]
if len(b) > len(a):
	le = len(b)
	print(2 ** (math.floor(math.log(r, 2)) + 1) - 1)
else:
	n = len(b)
	diff = r - l
	ans = ['1' for i in range(n)]
	for i in range(n):
		if a[i] == '0' and b[i] == '1':
			pass
		elif a[i] == '1' and b[i] == '0':
			pass
		else:
			po = 2 ** (n - 1 - i)
			if po > diff:
				ans[i] = '0'
	print(int(''.join(ans), 2))


(l, r) = map(int, input().split())
lxr = l ^ r
msb = 0
while lxr:
	msb += 1
	lxr >>= 1
m = 0
t = 1
while msb:
	m += t
	t <<= 1
	msb -= 1
print(m)


(l, r) = map(int, input().split())
for i in range(63, -1, -1):
	(mx, mn) = (r, l)
	if 1 << i & l and 1 << i & r:
		mx = (1 << i) - 1
		mx = r ^ 1 << i | mx
	elif 1 << i & l == 0 and 1 << i & r == 0:
		mn = (1 << i) - 1
		mn = l & mn ^ (l | 1 << i)
	if mx >= l and mx <= r and (mn >= l) and (mn <= r):
		(r, l) = (mx, mn)
print(l ^ r)


import sys
from math import floor
entrada = input()
entrada_str = list(entrada.split(' '))
entrada_int = list(map(int, entrada_str))
a = entrada_int[0]
b = entrada_int[1]
if a == b:
	print(0)
	sys.exit()
string_1 = ''
string_2 = ''
while a:
	if a % 2 == 0:
		string_1 = string_1 + '0'
	else:
		string_1 = string_1 + '1'
	a = floor(a / 2)
while b:
	if b % 2 == 0:
		string_2 = string_2 + '0'
	else:
		string_2 = string_2 + '1'
	b = floor(b / 2)
lista_1 = list(string_1)
lista_1.reverse()
contrario_1 = ''.join(lista_1)
lista_2 = list(string_2)
lista_2.reverse()
contrario_2 = ''.join(lista_2)
if len(string_1) != len(string_2):
	resposta = pow(2, len(string_2)) - 1
else:
	potencia = 0
	for i in range(len(string_1)):
		if contrario_1[i] != contrario_2[i]:
			break
		potencia += 1
	potencia = len(string_1) - potencia
	resposta = pow(2, potencia) - 1
print(resposta)


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
from math import log
(l, r) = kk()
i = msb = int(max(log(l, 2), log(r, 2)))
while 2 ** i & l == 2 ** i & r:
	i -= 1
	if i == -1:
		break
i += 1
print(2 ** i - 1)


(l, r) = map(int, input().split())
z = str(bin(l ^ r))[2:]
if int(z) == 0:
	print(0)
else:
	print(2 ** (len(z) - z.index('1')) - 1)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(l, r) = value()
ans = 0
R = len(bin(r)) - 2
for i in range(61):
	if l & 1 << i ^ r & 1 << i:
		ans = 2 ** (i + 1) - 1
print(ans)


(l, r) = map(int, input().split())
s = bin(l)[2:]
t = bin(r)[2:]
z = max(len(s), len(t))
s = '0' * (z - len(s)) + s
t = '0' * (z - len(t)) + t
i = 0
while i < z and s[i] == t[i]:
	i = i + 1
print(pow(2, z - i) - 1)


import sys
from math import gcd, sqrt, ceil, log2
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
import math
sys.setrecursionlimit(2 * 10 ** 5 + 10)
import heapq
from itertools import permutations
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_sum(bit, i):
	s = 0
	i += 1
	while i > 0:
		s += bit[i]
		i -= i & -i
	return s

def update(bit, n, i, v):
	i += 1
	while i <= n:
		bit[i] += v
		i += i & -i

def modInverse(b, m):
	g = math.gcd(b, m)
	if g != 1:
		return -1
	else:
		return pow(b, m - 2, m)

def primeFactors(n):
	sa = set()
	sa.add(n)
	while n % 2 == 0:
		sa.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			sa.add(i)
			n = n // i
	return sa

def seive(n):
	pri = [True] * (n + 1)
	p = 2
	while p * p <= n:
		if pri[p] == True:
			for i in range(p * p, n + 1, p):
				pri[i] = False
		p += 1
	return pri

def check_prim(n):
	if n < 0:
		return False
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def getZarr(string, z):
	n = len(string)
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and string[r - l] == string[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and string[r - l] == string[r]:
					r += 1
				z[i] = r - l
				r -= 1

def search(text, pattern):
	concat = pattern + '$' + text
	l = len(concat)
	z = [0] * l
	getZarr(concat, z)
	ha = []
	for i in range(l):
		if z[i] == len(pattern):
			ha.append(i - len(pattern) - 1)
	return ha

def mergeIntervals(arr):
	arr.sort(key=lambda x: x[0])
	m = []
	s = -10000
	max = -100000
	for i in range(len(arr)):
		a = arr[i]
		if a[0] > max:
			if i != 0:
				m.append([s, max])
			max = a[1]
			s = a[0]
		elif a[1] >= max:
			max = a[1]
	if max != -100000 and [s, max] not in m:
		m.append([s, max])
	return m

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def sol(n):
	seti = set()
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			seti.add(n // i)
			seti.add(i)
	return seti

def lcm(a, b):
	return a * b // gcd(a, b)

def debug(l, r):
	ans = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			if i != j:
				ans = max(i ^ j, ans)
	return ans
(l, r) = map(int, input().split())
ans1 = '0'
ans2 = ''
z = len(bin(r)) - len(bin(l))
(z1, z2) = (bin(l)[2:], bin(r)[2:])
ans = ''
if l == r:
	print(0)
	exit()
z1 = '0' * z + z1
flag1 = 0
flag2 = 0
for i in range(len(z1)):
	if z1[i] == '0' and z2[i] == '0':
		if flag2 == 0:
			ans += '0'
		else:
			ans += '1'
	elif z1[i] == '1' and z2[i] == '1':
		if flag2 == 0:
			ans += '0'
		else:
			ans += '1'
	elif z1[i] == '0' and z2[i] == '1':
		flag2 = 1
		ans += '1'
	else:
		ans += '1'
print(int(ans, 2))


n = input().split()
m = int(n[1])
n = int(n[0])
if m < n:
	c = m
	m = n
	n = c
c = ''
a = bin(m)[2:]
b = bin(n)[2:]
b = '0' * (len(a) - len(b)) + b
while a[0] == b[0] and len(a) != 0:
	c1 = str(int(a[0]) ^ int(b[0]))
	c += c1
	a = a[1:]
	b = b[1:]
	if len(a) == 0 or len(b) == 0:
		break
aa = max(len(b), len(a))
c = c + aa * '1'
c = int(c)
d = 1
p = 0
while c != 0:
	s = c % 10
	p += d * s
	d = d * 2
	c = c // 10
print(p)


import math
(n, m) = map(int, input().split())
a = int(math.log(n, 2)) + 1
b = int(math.log(m, 2)) + 1
if a != b:
	print(2 ** max(a, b) - 1)
else:
	k = bin(n)[2:]
	l = bin(m)[2:]
	c = 0
	if k == l:
		print(0)
	else:
		for i in range(a):
			if k[i] == l[i]:
				r = 1
			else:
				break
		c += 2 ** (a - i) - 1
		print(c)


def calc(n):
	cnt = 0
	while n > 0:
		cnt += 1
		n //= 2
	return cnt

def main():
	(l, r) = map(int, input().split())
	k1 = calc(l)
	k2 = calc(r)
	while k1 >= k2:
		l ^= 2 ** (k2 - 1)
		r ^= 2 ** (k1 - 1)
		if l == 0 and r == 0:
			print(0)
			return
		k1 = calc(l)
		k2 = calc(r)
	print(2 ** (k2 - 1) + 2 ** (k2 - 1) - 1)
	return
main()


(l, r) = [int(c) for c in input().split()]
p = l ^ r
c = 0
while p:
	c += 1
	p = p >> 1
resultado = 2 ** c - 1
print(resultado)


(a, b) = map(int, input().split())
(a, b) = (min(a, b), max(a, b))
A = bin(a)[2:]
B = bin(b)[2:]
A = '0' * (len(B) - len(A)) + A
diff = 0
for i in range(len(A)):
	if A[i] != B[i]:
		diff = len(A) - i
		break
print(2 ** diff - 1)


R = lambda : map(int, input().split())
(l, r) = R()
cnt = 0
while l != r:
	l >>= 1
	r >>= 1
	cnt += 1
print(2 ** cnt - 1)


(l, r) = tuple(map(int, input().split(' ')))
x = l ^ r
pow = 1
while pow <= x:
	pow *= 2
print(pow - 1)


from collections import defaultdict
_input = [int(num) for num in input().split(' ')]
l = _input[0]
r = _input[1]
if l != r:
	binary_r = bin(r)[2:]
	binary_l = bin(l)[2:].zfill(len(binary_r))
	max_idx_prefix = 0
	for (idx, l_digit) in enumerate(binary_l):
		if l_digit != binary_r[idx]:
			max_idx_prefix = idx
			break
	a_binary = [0 for num in range(len(binary_r))]
	a_binary[max_idx_prefix] = 0
	for idx in range(max_idx_prefix + 1, len(a_binary)):
		a_binary[idx] = 1
	b_binary = [0 for num in range(len(binary_r))]
	b_binary[max_idx_prefix] = 1
	a_binary = ''.join((str(digit) for digit in a_binary))
	b_binary = ''.join((str(digit) for digit in b_binary))
	a_binary = int(a_binary, 2)
	b_binary = int(b_binary, 2)
	max_xor = a_binary ^ b_binary
	print(max_xor)
else:
	print(l ^ r)


(l, r) = map(int, input().split())
for i in range(61)[::-1]:
	if l >> i & 1 != r >> i & 1:
		print((1 << i + 1) - 1)
		exit()
print(0)


line = input().split()
l = int(line[0])
r = int(line[1])
diff = r ^ l
print(pow(2, diff.bit_length()) - 1)


import math
(L, R) = map(int, input().strip().split())
if L == R:
	print(0)
else:
	p = int(math.log2(R))
	tar = 2 ** p
	while not tar > L:
		L -= tar
		R -= tar
		p = int(math.log2(R))
		tar = 2 ** p
	print(2 ** (p + 1) - 1)


def power(x, a):
	if a == 0:
		return 1
	z = power(x, a // 2)
	z *= z
	if a % 2:
		z *= x
	return z
[l, r] = list(map(int, input().split()))
(a, b) = (bin(l)[2:], bin(r)[2:])
(la, lb) = (len(a), len(b))
mx = max(la, lb)
a = '0' * (mx - la) + a
b = '0' * (mx - lb) + b
idx = 0
while idx < mx and (not int(a[idx]) ^ int(b[idx])):
	idx += 1
print(power(2, mx - idx) - 1)


def max_xor_naive(l, r):
	max_xor = 0
	xor = 0
	for a in range(l, r + 1):
		for b in range(a + 1, r + 1):
			xor = a ^ b
			if xor > max_xor:
				max_xor = xor
	return max_xor

def max_xor_efficient(l, r):
	s1 = bin(l)[2:]
	s2 = bin(r)[2:]
	l1 = len(s1)
	l2 = len(s2)
	if l1 < l2:
		return pow(2, l2) - 1
	x = 0
	for i in range(0, l1):
		if s1[i] != s2[i]:
			return pow(2, l1 - i) - 1
	return 0
(l, r) = map(int, input().split())
ans2 = max_xor_efficient(l, r)
print(ans2)


(l, r) = map(int, input().split(' '))
n1 = bin(l)[2:]
n2 = bin(r)[2:]
if l == r:
	print(0)
elif len(n1) < len(n2):
	print(int(len(n2) * '1', 2))
else:
	index = 0
	for i in range(len(n1)):
		if n1[i] != n2[i]:
			index = i
			break
	print(int((len(n1) - index) * '1', 2))


from math import log2
(l, r) = map(int, input().split())
if l == r:
	print('0')
else:
	print((1 << int(log2(l ^ r) + 1)) - 1)


(l, r) = map(int, input().split())
val = l ^ r
msb = 0
while val:
	msb += 1
	val >>= 1
maxxor = 0
two = 1
while msb:
	maxxor += two
	two <<= 1
	msb -= 1
print(maxxor)


(l, r) = map(int, input().split())
a = '{0:062b}'.format(l)
b = '{0:062b}'.format(r)
n = len(a)
i = 0
if l == r:
	print(0)
else:
	while i < n and a[i] == b[i]:
		i += 1
	print(2 ** (62 - i) - 1)


import math
(a, b) = [int(x) for x in input().split()]
while a != 0 and b != 0:
	x = int(math.log(a, 2))
	y = int(math.log(b, 2))
	if x != y:
		break
	a = a & ~(1 << x)
	b = b & ~(1 << y)
if a == 0 and b == 0:
	print(0)
else:
	if b > a:
		(a, b) = (b, a)
	x = int(math.log(a, 2)) + 1
	b = (1 << x) - 1
	a = a | b
	print(a)


import sys
(m, n) = map(int, sys.stdin.readline().split())
res = m ^ n
s = bin(res)
s = s[2:]
s = int(s)
if s == 0:
	print(0)
else:
	s = str(s)
	res = 2 ** len(s) - 1
	print(res)


import math
l1 = input().split()
l1 = [int(i) for i in l1]
l2 = l1[1]
l1 = l1[0]
x = l1 ^ l2
y = 1
while y <= x:
	y = y * 2
print(y - 1)


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 8
N = 5 * 10 ** 6

def solve(n):
	arr = []
	while n > 0:
		arr.append(n % 2)
		n = n // 2
	return arr
(l, r) = Ri()
arrl = solve(l)
arrr = solve(r)
if len(arrr) > len(arrl):
	ans = (1 << len(arrr)) - 1
	print(ans)
else:
	ind = -1
	for i in range(len(arrr) - 1, -1, -1):
		if arrr[i] != arrl[i]:
			ind = i
			break
	if ind == -1:
		print(0)
	else:
		ans = (1 << ind + 1) - 1
		print(ans)


(menor, maior) = list(map(int, input().split()))
a = 1
resultado = menor ^ maior
while a <= resultado:
	a *= 2
a -= 1
print(a)


from sys import stdin, stdout
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
(a, b) = map(int, input().split())
ans = '0'
if a == b:
	pass
else:
	x = bin(a)[2:]
	y = bin(b)[2:]
	if len(x) < len(y):
		ans = '1' * len(y)
	else:
		flag = 0
		for i in range(len(x)):
			if flag == 0:
				if x[i] != y[i]:
					ans = '1'
					flag = 1
			else:
				ans += '1'
print(int(ans, 2))


(l, r) = [int(i) for i in input().split()]
LXR = l ^ r
msbPos = 0
while LXR:
	msbPos += 1
	LXR >>= 1
(maxXOR, two) = (0, 1)
while msbPos:
	maxXOR += two
	two <<= 1
	msbPos -= 1
print(maxXOR)


def maximum(l, r):
	r = bin(r)[2:]
	l = bin(l)[2:].zfill(len(r))
	if r[0] == '1' and l[0] == '0':
		return int('1' * len(l), base=2)
	else:
		if l[1:] != '':
			l = int(l[1:], base=2)
			r = int(r[1:], base=2)
		else:
			return 0
		return maximum(l, r)
inp = input()
(l, r) = inp.split(' ')
print(maximum(int(l), int(r)))


def f(a, b):
	r = list(bin(b).lstrip('0b'))
	l = list((len(bin(b)) - len(bin(a))) * '0' + bin(a).lstrip('0b'))
	for i in range(len(r)):
		if r[i] == '1' and l[i] == '1':
			r[i] = '0'
			if int(''.join(r), 2) >= a:
				pass
			else:
				r[i] = '1'
		if l[i] == '0' and r[i] == '0':
			l[i] = '1'
			if int(''.join(l), 2) <= b:
				pass
			else:
				l[i] = '0'
	l = int(''.join(l), 2)
	r = int(''.join(r), 2)
	return l ^ r
(a, b) = map(int, input().strip().split())
print(f(a, b))


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	(l, r) = mi()
	s1 = bin(l)[2:]
	s2 = bin(r)[2:]
	if len(s1) != len(s2):
		print((1 << len(s2)) - 1)
		return
	x = 0
	for i in range(62, -1, -1):
		if l >> i & 1 ^ r >> i & 1:
			x += 1 << i + 1
			x -= 1
			break
	print(x)
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


(l, r) = map(int, input().split())
z = l ^ r
c = 0
if z == 0:
	print(0)
	exit()
while z:
	c += 1
	z >>= 1
x = '1' * c
print(int(x, 2))


import sys
(l, r) = map(int, sys.stdin.readline().split())
i = 64
while i >= 0:
	if 1 << i & l != 0 and 1 << i & r != 0 or (1 << i & l == 0 and 1 << i & r == 0):
		i -= 1
	else:
		break
print((1 << i + 1) - 1)