Given two integers, $\boldsymbol{l}$ and $\textbf{r}$, find the maximal value of $\boldsymbol{a}$ xor $\boldsymbol{b}$, written $a\oplus b$, where $\boldsymbol{a}$ and $\boldsymbol{b}$ satisfy the following condition:

$l\leq a\leq b\leq r$  

For example, if $l=11$ and $r=12$, then 

$\textbf{11}\oplus11=\textbf{0}$ 

$\textbf{11}\oplus12=7$ 

$12\oplus12=0$  

Our maximum value is $7$.  

Function Description

Complete the maximizingXor function in the editor below.  It must return an integer representing the maximum value calculated.  

maximizingXor has the following parameter(s):

l: an integer, the lower bound, inclusive  
r: an integer, the upper bound, inclusive  

Input Format

The first line contains the integer $\boldsymbol{l}$. 

The second line contains the integer $\textbf{r}$.    

Constraints

$1\leq l\leq r\leq10$^{3}  

Output Format

Return the maximal value of the xor operations for all permutations of the integers from $\boldsymbol{l}$ to $\textbf{r}$, inclusive.

Sample Input 0
10
15

Sample Output 0
7

Explanation 0

Here $l=10$ and $r=15$. Testing all pairs:   

$10\oplus10=0$ 

$10\oplus11=1$ 

$\textbf{10}\oplus12=\textbf{6}$ 

$\textbf{10}\oplus13=7$ 

$\textbf{10}\oplus\textbf{14}=4$ 

$10\oplus15=5$ 

$\textbf{11}\oplus11=\textbf{0}$ 

$\textbf{11}\oplus12=7$ 

$11\oplus13=6$ 

$11\oplus14=5$ 

$11\oplus15=4$ 

$12\oplus12=0$ 

$12\oplus13=1$ 

$\textbf{12}\oplus\textbf{14}=2$ 

$12\oplus15=3$ 

$13\oplus13=0$ 

$13\oplus14=3$ 

$13\oplus15=2$ 

$14\oplus14=0$ 

$14\oplus15=1$ 

$15\oplus15=0$  

Two pairs, (10, 13) and (11, 12) have the xor value 7, and this is maximal. 

Sample Input 1
11
100

Sample Output 1
127

Source: hackerrank | Difficulty: EASY
Tags: Bit manipulation


Solutions:
l = int(input())
r = int(input())
m = 0
for i in range(l, r + 1):
	for j in range(i + 1, r + 1):
		m = max(m, i ^ j)
print(m)


def max_xor(l, r):
	ans = 0
	for a in range(l, r + 1):
		for b in range(l, r + 1):
			ans = max(ans, a ^ b)
	return ans
l = int(input())
r = int(input())
print(max_xor(l, r))


import sys
L = int(sys.stdin.readline())
R = int(sys.stdin.readline())
print(max((A ^ B for A in range(L, R + 1) for B in range(L, R + 1))))


l = int(input())
r = int(input())
m = 0
for a in range(l, r + 1):
	for b in range(a + 1, r + 1):
		if a ^ b > m:
			m = a ^ b
print(m)


def maxXor(l, r):
	res = 0
	for a in range(l, r + 1):
		for b in range(a, r + 1):
			res = max(res, a ^ b)
	return res
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	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
	return (1 << i + 1) - 1
l = int(input())
r = int(input())
print(maxXor(l, r))


__author__ = '@nehemiahjacob'

def maxXor(l, r):
	max = 0
	for a in range(l, r + 1):
		for b in range(l, r + 1):
			xor = a ^ b
			if max < xor:
				max = xor
	return max
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	max = l ^ r
	for a in range(l, r + 1):
		for b in range(l, r + 1):
			if a ^ b > max:
				max = a ^ b
	return max
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	result = 0
	for a in range(l, r + 1):
		for b in range(l, r + 1):
			result = max(result, a ^ b)
	return result
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	x = l ^ r
	if x == 0:
		return 0
	ret = 1
	while ret <= x:
		ret <<= 1
	return ret - 1
l = int(input())
r = int(input())
print(maxXor(l, r))


l = int(input())
r = int(input())
ret = 0
for A in range(l, r + 1, 1):
	for B in range(l, r + 1, 1):
		ret = max(ret, A ^ B)
print(ret)


def maxXOR(l, r):
	k = l ^ r
	rt = 1
	while k:
		rt <<= 1
		k >>= 1
	return rt - 1
print(maxXOR(int(input()), int(input())))


def maxXor(l, r):
	(value, mask) = (0, 1)
	for i in range(0, 11):
		if mask & r ^ mask & l:
			value += mask
		elif mask & r:
			if r - mask >= l:
				r -= mask
				value += mask
		elif l + mask <= r:
			l += mask
			value += mask
		mask <<= 1
	return value
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	m = 0
	for i in range(l, r + 1):
		for j in range(i, r + 1):
			if i ^ j > m:
				m = i ^ j
	return m
l = int(input())
r = int(input())
print(maxXor(l, r))


import math
L = int(input())
R = int(input())
print(int(math.pow(2, (L ^ R).bit_length()) - 1))


def maxXor(l, r):
	maxv = 0
	for i in range(l, r + 1):
		for j in range(l + 1, r + 1):
			maxv = max(maxv, i ^ j)
	return maxv
l = int(input())
r = int(input())
print(maxXor(l, r))


import sys
L = int(sys.stdin.readline())
R = int(sys.stdin.readline())
print(max((A ^ B for A in range(L, R + 1) for B in range(L, R + 1))))


L = int(input())
R = int(input())
m = 0
for A in range(L, R + 1):
	for B in range(L, R + 1):
		m = max(m, A ^ B)
print(m)


def maxXor(l, r):
	max = 0
	for i in range(l, r + 1):
		for k in range(i + 1, r + 1):
			val = i ^ k
			max = val if val > max else max
	return max
l = int(input())
r = int(input())
print(maxXor(l, r))


(L, R) = (int(input()), int(input()))

def xors(L, R):
	xor = lambda x, y: x ^ y
	for A in range(L, R + 1):
		for B in range(A, R + 1):
			yield xor(A, B)
print(max(xors(L, R)))


l = int(input())
r = int(input())
max = 0
for i in range(l, r + 1):
	for j in range(i, r + 1):
		if i ^ j > max:
			max = i ^ j
print(max)


import math

def maxXor(l, r):
	bitL = bin(l)[2:]
	bitR = bin(r)[2:]
	b = 2 ** int(math.log(r, 2)) - 1
	bestAB_value = -1
	for b in range(l, r + 1):
		for a in range(l, r + 1):
			if a == b:
				continue
			binA = bin(a)[2:]
			binB = bin(b)[2:]
			compareLen = max(len(binA), len(binB))
			binA = '0' * (compareLen - len(binA)) + binA
			binB = '0' * (compareLen - len(binB)) + binB
			xorAB = ''
			for i in range(compareLen):
				if binA[i] == binB[i]:
					xorAB = xorAB + '0'
				else:
					xorAB = xorAB + '1'
					xorValue = int(xorAB, 2)
					if xorValue > bestAB_value:
						bestAB_value = xorValue
	return bestAB_value
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxxor(l, r):
	L = []
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			L.append(i ^ j)
	return max(L)
(l, r) = (int(input()), int(input()))
print(maxxor(l, r))


def maxXor(l, r):
	largest = 0
	for a in range(l, r + 1):
		for b in range(a, r + 1):
			if a ^ b > largest:
				largest = a ^ b
	return largest
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	a = l
	maxValue = 0
	while a <= r:
		b = l
		while b <= r:
			if a ^ b > maxValue:
				maxValue = a ^ b
			b += 1
		a += 1
	return maxValue
l = int(input())
r = int(input())
print(maxXor(l, r))


def bin_to_dec(bin_str):
	bin_list = list(bin_str)
	bin_list.reverse()
	dec_int = 0
	for i in range(len(bin_list)):
		dec_int += 2 ** i * int(bin_list[i])
	return dec_int

def dec_to_bin(dec_int):
	bin_str = ''
	while dec_int > 0:
		(quo, rem) = divmod(dec_int, 2)
		bin_str = str(rem) + bin_str
		dec_int = quo
	return bin_str

def xor(dec1, dec2):
	(bin1, bin2) = (dec_to_bin(dec1), dec_to_bin(dec2))
	if len(bin2) > len(bin1):
		(bin1, bin2) = (bin2, bin1)
	bin2 = '0' * (len(bin1) - len(bin2)) + bin2
	xor = ''
	for i in range(len(bin2)):
		if bin1[i] != bin2[i]:
			xor += '1'
		else:
			xor += '0'
	return bin_to_dec(xor)

def maxXor(l, r):
	xor_list = []
	for val1 in range(l, r + 1):
		for val2 in range(val1, r + 1):
			xor_list.append(xor(val1, val2))
	max_xor = max(xor_list)
	return max_xor
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	m = 0
	for a in range(l, r):
		for b in range(a + 1, r + 1):
			if a ^ b > m:
				m = a ^ b
	return m
l = int(input())
r = int(input())
print(maxXor(l, r))


l = int(input())
r = int(input())
highest = 0
for i in range(l, r + 1):
	for j in range(l, r + 1):
		test = i ^ j
		if test > highest:
			highest = test
print(highest)


def prog():
	(l, r) = [int(input()), int(input())]
	nums = []
	for a in range(r + 1)[l:]:
		for b in range(a + 1)[l:]:
			nums.append(b ^ a)
	print(max(nums))
prog()


def maxXor(l, r):
	lower = bin(l)[2:]
	upper = bin(r)[2:]
	if len(lower) < len(upper):
		for i in range(len(upper) - len(lower)):
			lower = '0' + lower
	final = ''
	for i in range(len(upper)):
		if upper[i] == lower[i]:
			if lower[i] == '0':
				if int(lower[:i] + '1' + lower[i + 1:], 2) < r:
					final += '1'
				elif int(upper[:i] + '1' + upper[i + 1:], 2) < r:
					final += '1'
				else:
					final += '0'
			elif int(lower[:i] + '0' + lower[i + 1:], 2) > l:
				final += '1'
			elif int(upper[:i] + '0' + upper[i + 1:], 2) > l:
				final += '1'
			else:
				final += '0'
		else:
			final += '1'
	print(int(final, 2))
	pass
l = int(input())
r = int(input())
maxXor(l, r)


def maxXor(l, r):
	curMax = 0
	for a in range(l, r + 1):
		for b in range(l, r + 1):
			curMax = max(curMax, a ^ b)
	return curMax
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	ret = 0
	for a in range(l, r + 1):
		for b in range(a, r + 1):
			ret = max(ret, a ^ b)
	return ret
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	return max((a ^ b for a in range(l, r + 1) for b in range(l, r + 1)))
l = int(input())
r = int(input())
print(maxXor(l, r))


(l, r) = (int(input()), int(input()))
dobee = []
for i in range(l, r + 1):
	for j in range(l, r + 1):
		dobee.append(i ^ j)
dobee.sort()
print(max(dobee))


import math

def xor(a, b):
	return a ^ b

def getDigits(num):
	return math.floor(math.log(num, 2)) + 1

def getLargest(digits):
	return 2 ** digits - 1
num = int(input())
num2 = int(input())
found = 0
if num == num2:
	largest = 0
else:
	digits = getDigits(num2)
	largest = getLargest(digits)
	while found == 0:
		for i in range(num2, num - 1, -1):
			if xor(i, largest) >= num and xor(i, largest) <= num2:
				found = 1
				break
		if found != 1:
			largest -= 1
			digits = getDigits(largest)
print(largest)


def maxXor(l, r):
	max_xor = 0
	for x in range(l, r + 1):
		for y in range(x, r + 1):
			max_xor = max(max_xor, x ^ y)
	return max_xor
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	max_xor = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			max_xor = max(max_xor, i ^ j)
	return max_xor
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	n1 = int.bit_length(l)
	n2 = int.bit_length(r)
	if n1 > n2:
		return 2 ** n1 - 1
	elif n2 > n1:
		return 2 ** n2 - 1
	else:
		return maxXor(l - 2 ** (n1 - 1), r - 2 ** (n1 - 1))
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	m = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			k = i ^ j
			if k > m:
				m = k
	return m
l = int(input())
r = int(input())
print(maxXor(l, r))


def max_xor(l, r):
	maximum = l ^ r
	for a in range(l, r - 1):
		for b in range(a + 1, r):
			maximum = max(maximum, a ^ b)
	return maximum
l = int(input())
r = int(input())
print(max_xor(l, r))


l = int(input())
r = int(input())
m = 0
for i in range(l, r + 1):
	for j in range(i + 1, r + 1):
		m = max(m, i ^ j)
print(m)


import operator

def maxXor(l, r):
	maxXor = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			if maxXor < operator.xor(i, j):
				maxXor = operator.xor(i, j)
	return maxXor
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	maximum_bits = r.bit_length()
	if l.bit_length() == r.bit_length():
		top_bit = 2 ** (r.bit_length() - 1)
		l_red = l - top_bit
		r_red = r - top_bit
		return maxXor(l_red, r_red)
	return 2 ** r.bit_length() - 1
l = int(input())
r = int(input())
print(maxXor(l, r))


a = int(input())
b = int(input())
m = 0
for i in range(a, b + 1):
	for j in range(a, b + 1):
		m = max(m, i ^ j)
print(m)


L = int(input())
R = int(input())
op = 0
for i in range(L, R):
	if i ^ i + 1 > op:
		op = i ^ i + 1
	else:
		continue
print(op)


def maxXor(l, r):
	xor = []
	for a in range(l, r + 1):
		for b in range(l, r + 1):
			if a != b:
				(A, B) = (bin(a)[2:], bin(b)[2:])
				width = max(len(A), len(B))
				(A, B) = (A.zfill(width), B.zfill(width))
				AxorB = ''.join(('0' if A[i] == B[i] else '1' for i in range(len(A))))
				xor.append(int(AxorB, 2))
	return max(xor)
l = int(input())
r = int(input())
print(maxXor(l, r))


print(2 ** (len(bin(int(input()) ^ int(input()))) - 2) - 1)


def maxXor(l, r):
	if l == r:
		return 0
	pow2k = 1
	while pow2k << 1 <= r:
		pow2k <<= 1
	if l & pow2k:
		return maxXor(l ^ pow2k, r ^ pow2k)
	else:
		return (pow2k << 1) - 1
l = int(input())
r = int(input())
print(maxXor(l, r))


l = int(input())
r = int(input())
xors = []
for i in range(l, r + 1):
	for j in range(i + 1, r + 1):
		xors.append(i ^ j)
print(max(xors))


def maxXor(l, r):
	max_xor = 0
	for b in range(l, r + 1):
		for a in range(l, b + 1):
			test_xor = int(bin(a ^ b), 2)
			if test_xor > max_xor:
				max_xor = test_xor
	return max_xor
l = int(input())
r = int(input())
print(maxXor(l, r))


def find_max_power2(r):
	i = 1
	while i << 1 <= r:
		i = i << 1
	return i

def maxXor(l, r):
	a = find_max_power2(r)
	while a <= l:
		a += find_max_power2(r - a)
	return a ^ a - 1
l = int(input())
r = int(input())
print(maxXor(l, r))


l = int(input())
r = int(input())
maxXor = -1
for a in range(l, r + 1):
	for b in range(a + 1, r + 1):
		if a ^ b > maxXor:
			maxXor = a ^ b
print(maxXor)


def maxXor(l, r):
	a = 0
	b = 0
	max = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			if i ^ j > max:
				max = i ^ j
				a = i
				b = j
	return max
l = int(input())
r = int(input())
print(maxXor(l, r))


import math

def maxXor(l, r):
	m = int(math.log(r, 2))
	z = 0
	if pow(2, m - 1) > l:
		l = pow(2, m - 1)
	for x in range(l, r + 1):
		for y in range(x, r + 1):
			if x ^ y > z:
				z = x ^ y
			if z == int(pow(2, m + 1)) - 1:
				return z
	return z
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	max = 0
	for a in range(l, r + 1):
		for b in range(a, r + 1):
			xor = a ^ b
			if xor > max:
				max = xor
	return max
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	max = 0
	for b in range(l, r + 1):
		for a in range(l, b + 1):
			if max < a ^ b:
				max = a ^ b
	return max
l = int(input())
r = int(input())
print(maxXor(l, r))


l = int(input())
r = int(input())
maximum = 0
for a in range(l, r + 1):
	for b in range(a, r + 1):
		if a ^ b > maximum:
			maximum = a ^ b
print(maximum)


def maxXor(l, r):
	maxNumber = 0
	for i in range(l, r):
		for j in range(i, r + 1):
			maxNumber = max(i ^ j, maxNumber)
	return maxNumber
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	res = 0
	for i in range(l, r + 1):
		for j in range(i, r + 1):
			if i ^ j > res:
				res = i ^ j
	return res
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	best = l ^ r
	for i in range(l, r + 1):
		for j in range(i, r + 1):
			best = max(best, i ^ j)
	return best
l = int(input())
r = int(input())
print(maxXor(l, r))


l = int(input())
u = int(input())
m = 0
for i in range(l, u + 1):
	for j in range(i + 1, u + 1):
		m = max(m, i ^ j)
print(m)


def maxXor(l, r):
	k = l ^ r
	k |= k >> 1
	k |= k >> 2
	k |= k >> 4
	k |= k >> 8
	return k
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	max = 0
	for i in range(l, r):
		for j in range(i, r + 1):
			xor = i ^ j
			if xor > max:
				max = xor
	return max
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	max_val = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			max_val = max(max_val, i ^ j)
	return max_val
l = int(input())
r = int(input())
print(maxXor(l, r))


(L, R) = (int(input()), int(input()))
max = None
for i in range(L, R + 1):
	for j in range(i + 1, R + 1):
		if max is None:
			max = i ^ j
		elif max < i ^ j:
			max = i ^ j
print(max)


L = int(input())
R = int(input())
br = [i for i in bin(R)[2:]]
bl = [i for i in bin(L)[2:].zfill(len(br))]
mask = 2 ** (len(br) + 1) - 1
sz = len(br)
output = ['0' for i in range(sz)]
for idx in range(sz):
	if br[idx] == '1':
		if bl[idx] == '0':
			pass
		elif int('0b' + ''.join(br[0:idx]) + '0' + '0' * (sz - idx - 1), 2) >= int('0b' + ''.join(bl), 2):
			br[idx] = '0'
	elif bl[idx] == '0':
		if int('0b' + ''.join(bl[0:idx]) + '1' + '0' * (sz - idx - 1), 2) <= int('0b' + ''.join(br), 2):
			bl[idx] = '1'
	else:
		pass
	output = (int('0b' + ''.join(bl), 2) ^ int('0b' + ''.join(br), 2)) & mask
print(output)


def maxXor(l, r):
	r = max((a ^ b for a in range(l, r + 1) for b in range(a + 1, r + 1)))
	return r
l = int(input())
r = int(input())
print(maxXor(l, r))


L = int(input())
R = int(input())
a = bin(L)
b = bin(R)
while len(a) < len(b):
	a = a[:2] + '0' + a[2:]
same_ones = []
same_zeroes = []
i = len(a) - 1
k = 0
while i > 1:
	if a[i] == '1' and b[i] == '1':
		same_ones.append(2 ** k)
	elif a[i] == '0' and b[i] == '0':
		same_zeroes.insert(0, 2 ** k)
	i -= 1
	k += 1
A = L
B = R
for item in same_zeroes:
	if A + item <= R:
		A += item
for item in same_ones:
	if B - item >= A:
		B -= item
print(A ^ B)


def maxXor(l, r):
	[x, y] = [0, 0]
	value = 0
	for i in range(l, r + 1):
		for j in range(i, r + 1):
			if i ^ j > value:
				[x, y] = [i, j]
				value = i ^ j
	return value
l = int(input())
r = int(input())
print(maxXor(l, r))


def findmx(l, r):
	mx = 0
	a = l
	while a <= r:
		b = a
		while b <= r:
			temp = a ^ b
			if temp > mx:
				mx = temp
			b = b + 1
		a = a + 1
	return mx
l = int(input())
r = int(input())
print(findmx(l, r))


def decToBin(n):
	exp = 1
	output = ''
	while exp * 2 <= n:
		exp = exp * 2
	while exp > 0:
		if n >= exp:
			output += '1'
			n -= exp
		else:
			output += '0'
		exp = exp // 2
	return int(output)

def XOR(n1, n2):
	if n1 == 0 and n2 == 0:
		return ''
	if n1 % 10 + n2 % 10 == 1:
		return XOR(n1 // 10, n2 // 10) + '1'
	else:
		return XOR(n1 // 10, n2 // 10) + '0'

def solvePuzzle(n1, n2):
	bestYet = 0
	for i in range(n1, n2 + 1, 1):
		for j in range(i, n2 + 1, 1):
			x = XOR(decToBin(i), decToBin(j))
			if int(x, 2) > bestYet:
				bestYet = int(x, 2)
	return bestYet
l = int(input())
r = int(input())
assert 1 <= l <= r <= 1000
print(solvePuzzle(l, r))


def maxXor(l, r):
	mmax = 0
	for a in range(l, r + 1):
		for b in range(a, r + 1):
			mmax = max(mmax, a ^ b)
	return mmax
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	abin = list(bin(l)[2:])
	bbin = list(bin(r)[2:])
	abin = (len(bbin) - len(abin)) * ['0'] + abin
	a = l
	b = r
	val = 2 ** (len(bbin) - 1)
	maxXor = 0
	for i in range(len(bbin)):
		if bbin[i] == abin[i]:
			if bbin[i] == '0':
				if a + val <= r:
					abin[i] = '1'
					a += val
				elif b + val <= r:
					bbin[i] = '1'
					b += val
			elif a - val >= l:
				abin[i] = '0'
				a -= val
			elif b - val >= l:
				bbin[i] = '0'
				b -= val
		if bbin[i] != abin[i]:
			maxXor += val
		val //= 2
	return maxXor
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	m = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			k = i ^ j
			if k > m:
				m = k
	return m
l = int(input())
r = int(input())
print(maxXor(l, r))


l = int(input())
r = int(input())
if l > r:
	(l, r) = (r, l)
max_v = 0
for i in range(l, r + 1):
	for j in range(l, r + 1):
		max_v = max(max_v, i ^ j)
print(max_v)


l = int(input())
r = int(input())
assert 1 <= l <= r
assert r <= 10 ** 3
max_val = -1
for i in range(l, r + 1):
	for j in range(l, r + 1):
		cur_val = i ^ j
		if max_val < cur_val:
			max_val = cur_val
print(max_val)


import sys
l = int(sys.stdin.readline())
r = int(sys.stdin.readline())
maxXOR = 0
i = l
while i <= r:
	j = i + 1
	while j <= r:
		x = i ^ j
		if x > maxXOR:
			maxXOR = x
		j += 1
	i += 1
print(maxXOR)


def maxXor(l, r):
	max_xor = 0
	for a in range(l, r + 1):
		for b in range(a, r + 1):
			max_xor = max(max_xor, a ^ b)
	return max_xor
l = int(input())
r = int(input())
print(maxXor(l, r))


L = int(input())
R = int(input())
answer = 0
for a in range(L, R + 1):
	for b in range(a, R + 1):
		answer = max(answer, a ^ b)
print(answer)


def maxXor(l, r):
	return max([x ^ y for x in range(l, r + 1) for y in range(l, r + 1)])
l = int(input())
r = int(input())
print(maxXor(l, r))


from math import log
import math

def Xor(c, d):
	a = int(c)
	b = int(d)
	k = int(math.log(a, 2))
	f = int(math.log(b, 2))
	j = max(a, b)
	d = min(a, b)
	e = max(k, f)
	q = bin(j)
	w = bin(d)
	x = q[2:]
	y = w[2:]
	up = abs(k - f)
	z = '0' * up + y
	count = 0
	for a in range(0, e + 1):
		if x[a] == '0' and z[a] == '1':
			count += 2 ** (e - a)
		elif x[a] == '1' and z[a] == '0':
			count += 2 ** (e - a)
	return count

def maxXor(c, d):
	maxe = -9001
	a = int(c)
	b = int(d)
	for x in range(a, b + 1):
		for y in range(x, b + 1):
			if Xor(x, y) > maxe:
				maxe = int(Xor(x, y))
	return maxe
l = int(input())
r = int(input())
print(maxXor(l, r))


from operator import xor

def maxXor(l, r):
	xors = []
	for i in range(l, r + 1):
		for j in range(i, r + 1):
			xors.append(xor(i, j))
	return max(xors)
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	limit = l ^ r
	result = 1
	while limit:
		result = result << 1
		limit = limit >> 1
	return result - 1
l = int(input())
r = int(input())
print(maxXor(l, r))


import sys
import math
p = int(input())
q = int(input())
max = -1
for i in range(p, q):
	for j in range(i + 1, q + 1):
		if i ^ j > max:
			max = i ^ j
print(max)


def binarynum(num, length=1):
	return format(num, '#0{}b'.format(length + 2))[2:]

def maxXor(l, r):
	right = binarynum(r)
	left = binarynum(l, len(right))
	right_t = list(right)
	left_t = list(left)
	for i in range(len(right)):
		if right[i] == '1' and left[i] == '1':
			right_t[i] = '0'
			if right_t < left_t:
				right_t[i] = '1'
		if right[i] == '0' and left[i] == '0':
			left_t[i] = '1'
			if right_t < left_t:
				left_t[i] = '0'
	rr = int('0b' + ''.join(right_t), 2)
	ll = int('0b' + ''.join(left_t), 2)
	return rr ^ ll
l = int(input())
r = int(input())
print(maxXor(l, r))


def solve(L, R):

	def bit(n, pos):
		return n & 1 << pos

	def max_num(bit_length):
		return (1 << bit_length) - 1
	(l_bits, r_bits) = (L.bit_length(), R.bit_length())
	if l_bits != r_bits:
		return max_num(max(l_bits, r_bits))
	for i in range(l_bits - 1, -1, -1):
		if bit(L, i) != bit(R, i):
			return max_num(i + 1)
	return L ^ R

def main():
	L = int(input())
	R = int(input())
	print(solve(L, R))
main()


l = int(input())
r = int(input())

def maxXor(l, r):
	max_val = -1
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			cur_val = i ^ j
			if max_val < cur_val:
				max_val = cur_val
	return max_val
print(maxXor(l, r))


def maxXor(l, r):
	ret = -1
	for i in range(l, r + 1):
		for j in range(i, r + 1):
			ret = max(ret, i ^ j)
	return ret
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	res = -1
	for i in range(l, r):
		for j in range(i + 1, r + 1):
			res = max(res, i ^ j)
	return res
print(maxXor(int(input()), int(input())))


def maxXor(l, r):
	maxx = 0
	for i in range(l, r + 1):
		for j in range(i, r + 1):
			val = i ^ j
			if val > maxx:
				maxx = val
	return maxx
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	res = 0
	for i in range(l, r + 1):
		for j in range(i + 1, r + 1):
			res = max(res, i ^ j)
	return res
l = int(input())
r = int(input())
print(maxXor(l, r))


def max_xor(l, r):
	mx = 0
	for i in range(l, r + 1):
		for j in range(l, r + 1):
			if i > j:
				continue
			if i ^ j > mx:
				mx = i ^ j
	return mx
l = int(input())
r = int(input())
print(max_xor(l, r))


def maxXor(l, r):
	fa = lambda a: max(map(lambda b: b ^ a, range(a, r + 1)))
	return max(map(fa, range(l, r + 1)))
l = int(input())
r = int(input())
print(maxXor(l, r))


def maxXor(l, r):
	r = [i for i in range(l, r + 1)]
	max = 0
	for x in r:
		for y in r:
			if max < x ^ y:
				max = x ^ y
	return max
l = int(input())
r = int(input())
print(maxXor(l, r))


import sys

def solve(L, R):
	s = 0
	for B in range(L, R + 1):
		for A in range(B, R + 1):
			if A ^ B > s:
				s = A ^ B
	print(s)
L = int(sys.stdin.readline().strip())
R = int(sys.stdin.readline().strip())
solve(L, R)


int1 = int(input())
int2 = int(input())
max1 = 0
for i in range(int1, int2 + 1):
	for j in range(int1, int2 + 1):
		x = i ^ j
		if x > max1:
			max1 = x
print(max1)


def findGreatestXOR(lowerBound, upperBound):
	greatestXOR = 0
	for i in range(lowerBound, upperBound + 1):
		for j in range(i, upperBound + 1):
			if i ^ j > greatestXOR:
				greatestXOR = i ^ j
	return greatestXOR
lowerBound = int(input())
upperBound = int(input())
print(findGreatestXOR(lowerBound, upperBound))


def max_xor(l, r):
	ans = 0
	for a in range(l, r + 1):
		for b in range(l, r + 1):
			ans = max(ans, a ^ b)
	return ans
l = int(input())
r = int(input())
print(max_xor(l, r))


l = int(input())
r = int(input())
m = 0
for i in range(l, r + 1):
	for j in range(l, r + 1):
		x = int(bin(i), 2) ^ int(bin(j), 2)
		m = max(m, x)
print(m)


line1 = input()
line2 = input()
max = 0
for i in range(int(line1), int(line2) + 1):
	for l in range(i, int(line2) + 1):
		xor = int(i) ^ int(l)
		if xor > max:
			max = xor
print(max)