Let's denote as $\text{popcount}(x)$ the number of bits set ('1' bits) in the binary representation of the non-negative integer x.

You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and $\text{popcount}(x)$ is maximum possible. If there are multiple such numbers find the smallest of them.


-----Input-----

The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).

Each of the following n lines contain two integers l_{i}, r_{i} — the arguments for the corresponding query (0 ≤ l_{i} ≤ r_{i} ≤ 10^18).


-----Output-----

For each query print the answer in a separate line.


-----Examples-----
Input
3
1 2
2 4
1 10

Output
1
3
7



-----Note-----

The binary representations of numbers from 1 to 10 are listed below:

1_10 = 1_2

2_10 = 10_2

3_10 = 11_2

4_10 = 100_2

5_10 = 101_2

6_10 = 110_2

7_10 = 111_2

8_10 = 1000_2

9_10 = 1001_2

10_10 = 1010_2

Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Constructive algorithms
Skill types: Bit manipulation

Starter code:

Solutions:
import math
import sys
n = int(sys.stdin.readline())

def f(l, r):
	if l == r:
		return l
	t = int(math.log2(r))
	if 2 ** t <= l:
		return f(l - 2 ** t, r - 2 ** t) + 2 ** t
	elif 2 ** (t + 1) - 1 <= r:
		return 2 ** (t + 1) - 1
	else:
		return 2 ** t - 1
for _ in range(n):
	(l, r) = tuple(map(int, sys.stdin.readline().split()))
	print(f(l, r))


def main():
	cases = int(input())
	for i in range(cases):
		(left, right) = list(map(int, str(input()).split(' ')))
		res = left
		for j in range(65):
			if 1 << j & left == 0:
				if res | 1 << j > right:
					break
				res |= 1 << j
		print(res)
main()


for _ in range(0, int(input())):
	(l, r) = map(int, input().split())
	g = bin(l).replace('0b', '')
	d = len(bin(r)) - len(bin(l))
	n = g[::-1]
	n += d * '0'
	t = l
	for i in range(0, len(n)):
		if n[i] == '0':
			t += 2 ** i
			if t > r:
				break
			else:
				l = t
	print(l)


import math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

def In():
	return map(int, sys.stdin.readline().split())

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

def Pr(x):
	sys.stdout.write(str(x) + '\n')

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gte(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(a, b) = In()
		if b - a == 0:
			print(a)
		elif b - a == 1:
			print(b) if b & 1 else print(a)
		else:
			(s, t) = (bin(a)[2:], bin(b)[2:])
			for i in range(len(t) - len(s)):
				s = '0' + s
			ans = []
			ok = 0
			for i in range(len(t)):
				if t[i] == '1' and s[i] == '0':
					ans.append('0')
					for j in range(len(t) - len(ans)):
						ans.append('1')
					ok = 1
					break
				if ok:
					break
				else:
					ans.append(t[i])
			if t.count('1') > ans.count('1'):
				print(b)
				return
			ans = int(''.join(ans), 2)
			print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for q in range(t):
	(low, high) = map(int, input().split())
	val = 1
	ans = low
	while low < high:
		low = low | val
		if low > high:
			break
		ans = low
		val = val + val
	print(ans)


for i in range(int(input())):
	(m, n) = map(int, input().split())
	while m | m + 1 <= n:
		m |= m + 1
	print(m)


for q in range(int(input())):
	(l, r) = map(int, input().split())
	p = 0
	while l | 1 << p <= r:
		l |= 1 << p
		p += 1
	print(l)


def main():
	for _ in range(int(input())):
		(l, r) = map(int, input().split())
		mask = 1
		while l <= r:
			x = l
			l |= mask
			mask <<= 1
		print(x)
main()


def GETBIT(x, bit):
	return x >> bit & 1
test = int(input())
while test > 0:
	test -= 1
	(l, r) = map(int, input().split())
	pos = 63
	x = -1
	cnt = 0
	ans = 0
	while pos >= 0:
		if GETBIT(r, pos) == 1:
			if GETBIT(l, pos) == 0:
				x = pos
				break
			cnt += 1
			ans += 1 << pos
		pos -= 1
	if x == -1:
		print(ans)
	else:
		rs = cnt
		pre = ans
		while pos >= 0:
			if GETBIT(r, pos) == 1:
				if rs < cnt + pos:
					rs = cnt + pos
					ans = pre + (1 << pos) - 1
				cnt += 1
				pre += 1 << pos
				if rs < cnt:
					rs = cnt
					ans = pre
			pos -= 1
		print(ans)


from sys import stdin
input = stdin.readline

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

def fail():
	print(-1)
	exit()
t = int(input())
for _ in range(t):
	(l, r) = put()
	while l | l + 1 <= r:
		l = l | l + 1
	print(l)


n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	bit = 0
	while a | 1 << bit <= b:
		a = a | 1 << bit
		bit += 1
	print(a)


import os
import sys
from io import BytesIO, IOBase

def main():
	po = [1]
	for i in range(60):
		po.append(po[-1] * 2)
	for _ in range(int(input())):
		(l, r) = map(int, input().split())
		if l == r:
			print(l)
		else:
			br = bin(r)[2:]
			(lr, su) = (len(br), 0)
			if po[lr] - 1 == r:
				print(r)
			else:
				(ma, z, ele) = (0, 0, 0)
				for i in range(lr):
					if br[i] == '1':
						if su + po[lr - i - 1] - 1 >= l:
							if ma < z + (lr - 1 - i):
								ma = z + (lr - 1 - i)
								ele = su + po[lr - i - 1] - 1
							elif ma == z + (lr - i - 1):
								ele = min(ele, su + po[lr - i - 1] - 1)
						su += po[lr - i - 1]
						z += 1
				print(r if z > ma else ele)
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')
main()


T = int(input())
for _ in range(T):
	(l, r) = map(int, input().split(' '))
	(mask, ans, cnt) = (l, l, 0)
	while mask <= r:
		ans = mask
		mask = mask | 1 << cnt
		cnt += 1
	print(ans)


from sys import stdin
__author__ = 'artyom'
n = int(stdin.readline().strip())
for i in range(n):
	(l, r) = list(map(int, stdin.readline().strip().split()))
	(x, p) = (l, 1)
	while 1:
		x |= p
		if x > r:
			break
		p = p << 1 | 1
		l = x
	print(l)


for i in range(int(input())):
	(l, r) = map(int, input().split())
	L = list(bin(l))
	R = list(bin(r))
	L = L[2:]
	R = R[2:]
	w = 0
	c = 0
	L = ['0'] * (len(R) - len(L)) + L
	ans = 0
	if l == r:
		print(l)
		continue
	for i in range(len(R)):
		if L[i] != R[i]:
			for j in range(i + 1, len(R)):
				if R[j] == '0':
					w = 1
			if w == 1:
				ans = c + 2 ** (len(R) - i - 1) - 1
				break
			else:
				ans = c + 2 ** (len(R) - i) - 1
				break
		elif L[i] == '1':
			c = c + 2 ** (len(R) - i - 1)
	print(ans)


def get(l, r):
	while l | l + 1 <= r:
		l |= l + 1
	return l
q = int(input())
for i in range(q):
	(l, r) = list(map(int, input().split()))
	print(get(l, r))


import sys

def binary(a):
	s = ''
	for i in range(64):
		if a % 2 == 0:
			s += '0'
		else:
			s += '1'
		a //= 2
	return s

def dec(s):
	resp = 0
	for k in s:
		resp *= 2
		if k == '1':
			resp += 1
	return resp

def solve(a, b):
	x = binary(a)
	y = binary(b)
	resp = 0
	gen = ''
	for i in range(len(x) - 1, -1, -1):
		if x[i] == y[i]:
			gen += x[i]
		else:
			ones = True
			for j in range(i, -1, -1):
				if y[j] == '0':
					ones = False
					break
			if ones:
				gen += '1'
			else:
				gen += '0'
			for j in range(i - 1, -1, -1):
				gen += '1'
			break
	return dec(gen)
casos = int(input())
for i in range(casos):
	line = input()
	v = [int(x) for x in line.split()]
	print(solve(v[0], v[1]))


from sys import stdin, stdout
from math import ceil
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
p2 = [1]
for i in range(1, 64):
	p2 += [p2[-1] * 2]

def sb(x):
	c = 0
	while x > 0:
		x = x & x - 1
		c += 1
	return c
for _ in range(nmbr()):
	(l, r) = lst()
	sets = [0] * 64
	for bp in range(64):
		if r >> bp & 1:
			sets[bp] = 1 + sets[max(bp - 1, 0)]
		else:
			sets[bp] = sets[max(bp - 1, 0)]
	mx = sets[-1]
	init = mx
	ans = r
	for bp in range(64):
		if r >> bp & 1:
			new = r ^ p2[bp] | p2[bp] - 1
			if new >= l:
				ans = new
	if sb(r) > sb(ans):
		print(r)
	else:
		print(ans)


def fun(x, y):
	if x == y:
		return x
	if y & y + 1 == 0:
		return y
	[a, b] = [len(bin(x)) - 3, len(bin(y)) - 3]
	if a == b:
		return 1 << a | fun(1 << a ^ x, 1 << a ^ y)
	return (1 << b) - 1

def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	[n] = get()
	for z in range(n):
		[x, y] = get()
		print(fun(x, y))
	if mode == 'file':
		f.close()
main()


for i in range(int(input())):
	(a, b) = map(int, input().split())
	pow = 0
	while a | 1 << pow <= b:
		a |= 1 << pow
		pow += 1
	print(a)


def solve():
	(a, b) = [int(x) for x in input().split()]
	l = b - a + 1
	for i in range(64):
		if a & 1 << i:
			continue
		if a | 1 << i > b:
			break
		a |= 1 << i
	print(a)
n = int(input())
for i in range(n):
	solve()


import sys
L = lambda x: x.bit_length() if x > 0 else 1
n = int(input())
while n > 0:
	n -= 1
	(l, r) = list(map(int, sys.stdin.readline().split()))
	a = 0
	while L(l) == L(r) and r > 0:
		u = 1 << L(r) - 1
		l -= u
		r -= u
		a += u
	u = 1 << L(r) - 1
	if u + u - 1 == r and r > 1:
		u <<= 1
	print(a + u - 1)


for _ in range(int(input())):
	X = list(map(int, input().split()))
	Answer = X[0]
	Count = bin(Answer).count('1')
	for i in range(len(bin(X[1])) - 2):
		Temp = Answer | 1 << i
		Check = (1 if Answer != Temp else 0) + Count
		if Temp in range(X[0], X[1] + 1) and Check > Count:
			Answer = Temp
			Count = Check
	print(Answer)


from sys import stdin

def parseline(line):
	return list(map(int, line.split()))

def round_to_power_of_2(k):
	k |= k >> 1
	k |= k >> 2
	k |= k >> 4
	k |= k >> 8
	k |= k >> 16
	k += 1
	return k

def is_power_of_2(k):
	return 0 == k & k - 1
lines = list(filter(None, stdin.read().split('\n')))
lines = list(map(parseline, lines))
(n,) = lines[0]
for (li, ri) in lines[1:n + 1]:
	z = round_to_power_of_2(li ^ ri)
	mask = z - 1
	if is_power_of_2((ri & mask) + 1):
		print(ri)
	else:
		pos = z >> 1
		print(ri ^ pos | pos - 1)


t = int(input())
while t:
	(l, r) = map(int, input().split())
	s = '1'
	while l <= r:
		ans = l
		l |= l + 1
	print(ans)
	t -= 1


casos = int(input())
for i in range(casos):
	(x, y) = map(int, input().split())
	while x | x + 1 <= y:
		x |= x + 1
	print(x)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		(l, r) = map(int, input().split(' '))
		rlist = [int(x) for x in bin(r)[2:]]
		llist = [int(x) for x in bin(l)[2:]]
		llist.reverse()
		cnt = sum(llist)
		for x in range(len(rlist)):
			if x >= len(llist):
				if l + 2 ** x <= r:
					l += 2 ** x
					cnt += 1
			elif llist[x] == 0:
				if l + 2 ** x <= r:
					l += 2 ** x
					cnt += 1
		print(l)
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')
main()


import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
	(l, r) = list(map(int, input().split()))
	a = bin(l)[2:][::-1] + '0' * 65
	n = len(a)
	for i in range(n):
		if a[i] != '1':
			b = a[:i] + '1' + a[i + 1:]
			if int(b[::-1], 2) <= r:
				a = b
			else:
				break
	print(int(a[::-1], 2))


n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	bits = 0
	result = 0
	while True:
		count_bit = len(str(bin(r))) - 2
		if (1 << count_bit) - 1 == r:
			result += (1 << count_bit) - 1
			break
		exp = (1 << count_bit - 1) - 1
		if exp >= l:
			result += exp
			break
		else:
			bits += 1
			exp = 1 << count_bit - 1
			result += exp
			l -= exp
			r -= exp
	print(result)


import math
t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	a = 0
	b = 0
	if r:
		b = int(math.log2(r + 1))
	if l:
		a = int(math.log2(l))
	if b > a:
		print(2 ** b - 1)
	else:
		i = 0
		ans = l
		while ans | 1 << i <= r:
			ans = ans | 1 << i
			i += 1
		print(ans)


from sys import stdin

def CF_484_A():

	def countBits(n):
		cnt = 0
		while n:
			cnt += 1
			n >>= 1
		return cnt

	def countSetBits(n):
		count = 0
		while n:
			count += n & 1
			n >>= 1
		return count
	t = int(stdin.readline())
	while t:
		t -= 1
		a = [int(x) for x in stdin.readline().split()]
		cntA = countBits(a[0])
		cntB = countBits(a[1])
		if cntB > cntA:
			if countSetBits(a[1]) == cntB:
				print(a[1])
			else:
				print((1 << cntB - 1) - 1)
		else:
			a[0] <<= cntB - cntA
			for i in range(0, cntB + 1):
				res = a[0] | 1 << i
				if res > a[1]:
					break
				a[0] = res
			print(a[0])
CF_484_A()


from math import ceil, sqrt, log, gcd

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

def si():
	return input()

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

def li():
	return list(mi())

def main():
	n = ii()
	for i in range(n):
		(l, r) = mi()
		s1 = bin(r)[2:]
		n1 = len(s1)
		s2 = bin(l)[2:]
		s2 = '0' * (n1 - len(s2)) + s2
		s2 = list(s2)
		s1 = list(s1)
		x = s1.count('1')
		f = 0
		f1 = -1
		for i in range(n1):
			if f == 1:
				s2[i] = '1'
			elif s1[i] != s2[i]:
				f1 = i
				f = 1
		if f1 != -1:
			s3 = s2[:]
			s3[f1] = '1'
			s3 = ''.join(s3)
			x = int(s3, 2)
			if x <= r:
				print(x)
			else:
				s2 = ''.join(s2)
				print(int(s2, 2))
		else:
			s2 = ''.join(s2)
			print(int(s2, 2))
main()


for i in range(int(input())):
	(l, r) = map(int, input().split())
	while l <= r:
		(f, l) = (l, l | l + 1)
	print(f)


for _ in range(int(input())):
	(l, r) = list(map(int, input().split()))
	n = l
	i = 0
	while True:
		if n & 1 << i:
			pass
		elif n | 1 << i <= r:
			n = n | 1 << i
		else:
			break
		i += 1
	print(n)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	n = a
	while n <= b:
		an = n
		n |= n + 1
		if n > b:
			break
	print(an)


t = int(input())
for _ in range(t):
	(l, r) = map(int, input().split())
	p = l
	q = r
	i = -1
	j = -1
	while p:
		p = p >> 1
		i += 1
	while q:
		q = q >> 1
		j += 1
	s = max(i, j)
	n = l
	while s >= 0:
		if l >> s & 1 != r >> s & 1:
			break
		s -= 1
	s -= 1
	while s >= 0:
		n |= 1 << s
		s -= 1
	if n & r == n:
		print(r)
	else:
		print(n)


from math import log2

def solve(a, b):
	if a == b:
		return a
	x = int(log2(b))
	if 2 ** x <= a:
		return solve(a - 2 ** x, b - 2 ** x) + 2 ** x
	if 2 ** (x + 1) - 1 <= b:
		return 2 ** (x + 1) - 1
	return 2 ** x - 1
x = int(input())
for i in range(x):
	(a, b) = map(int, input().split(' '))
	print(solve(a, b))


def ispowerof2(x):
	return x and (not x & x - 1)

def largestpowerof2lessthan(n):
	s = bin(n)
	s = s[2:]
	if ispowerof2(n):
		return n
	s = s[1:]
	return int(pow(2, len(s)))

def solve(l, r):
	if ispowerof2(r + 1):
		return r
	ll = largestpowerof2lessthan(r)
	if ll - 1 >= l:
		return ll - 1
	return solve(l - ll, r - ll) + ll
t = int(input())
while t > 0:
	t -= 1
	(l, r) = [int(x) for x in input().split()]
	ans = solve(l, r)
	print(ans)


def solve(l, r):
	i = 62
	while i >= 0 and l & 1 << i == r & 1 << i:
		i -= 1
	if i < 0:
		return l
	for c in [r | (1 << i + 1) - 1, l | (1 << i) - 1]:
		if c <= r:
			return c
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	print(solve(l, r))


class CodeforcesTask484ASolution:

	def __init__(self):
		self.result = ''
		self.query_count = 0

	def read_input(self):
		self.query_count = int(input())

	def process_task(self):
		for x in range(self.query_count):
			range_binds = [int(x) for x in input().split(' ')]
			upper = bin(range_binds[1])
			lower = bin(range_binds[0])
			if upper == lower:
				print(range_binds[0])
			elif len(upper) > len(lower):
				if len(upper) > 5:
					if upper.count('1') == len(upper) - 2:
						print(range_binds[1])
					else:
						print(int('0b' + '1' * (len(upper) - 3), 2))
				else:
					nums = [bin(x) for x in range(range_binds[0], range_binds[1] + 1)]
					numsc = [x.count('1') for x in nums]
					searched = max(numsc)
					print(int(nums[numsc.index(searched)], 2))
			else:
				same_part = 3
				for x in range(3, len(upper)):
					if upper[x] != lower[x]:
						same_part = x - 2
						break
				if upper[same_part + 2:].count('1') == len(upper) - same_part - 2:
					print(range_binds[1])
				else:
					print(int(upper[:same_part + 2] + '0' + '1' * (len(upper) - same_part - 3), 2))

	def get_result(self):
		return self.result
Solution = CodeforcesTask484ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
for _ in range(0, n):
	(l, r) = map(int, input().split())
	while l | l + 1 <= r:
		l = l | l + 1
	print(l)


from sys import stdin as si
from collections import Counter as c

class Solution:

	def largest_one(self, a):
		return (1 << len(bin(a)) - 3) - 1

	def largest_pow_2(self, a):
		return 1 << len(bin(a)) - 3

	def bazinga(self, n, m):
		if n == m:
			return n
		elif m & m + 1 == 0:
			return m
		if len(bin(n)) < len(bin(m)):
			return self.largest_one(m)
		else:
			np2 = self.largest_pow_2(m)
			if n < np2 < m:
				return np2 - 1
			return self.bazinga(n - np2, m - np2) + np2
for i in range(int(si.readline().strip())):
	(n, m) = map(int, si.readline().strip().split())
	S = Solution()
	print(S.bazinga(n, m))


n = int(input())
while n:
	n = n - 1
	s = input()
	li = s.split(' ')
	l = int(li[0])
	r = int(li[1])
	ans = r
	while r >= l:
		ans = r
		r = r & r + 1
		r = r - 1
	print(ans)


def answer(l, r):
	if l == r:
		return l
	p = len(bin(r)[2:]) - 1
	num = 1 << p
	val = (1 << p + 1) - 1
	if num <= l:
		return answer(l - num, r - num) + num
	elif val == r:
		return val
	else:
		return num - 1
n = int(input())
for x in range(n):
	[l, r] = [int(i) for i in input().split()]
	print(answer(l, r))


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())

def dp(l, r):
	(lr, ll) = (len(bin(r)), len(bin(l)))
	if l == r:
		return r
	elif lr < len(bin(r + 1)):
		return r
	elif ll < lr:
		return 2 ** (lr - 3) - 1
	else:
		msb = 2 ** (lr - 3)
		return msb + dp(l - msb, r - msb)
for q in range(ii()):
	(l, r) = kk()
	print(dp(l, r))


import sys
input = sys.stdin.readline
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	while l | l + 1 <= r:
		l |= l + 1
	print(l)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = 1
	ans = []
	while x <= b:
		x <<= 1
		c = x - 1
		if c >= a and c <= b:
			ans.append(c)
	if len(ans) == 0:
		t = bin(a)
		text = list(str(t))
		ans.append(a)
		for i in range(len(text) - 1, -1, -1):
			if text[i] == '0':
				text[i] = '1'
				num = ''.join(text)
				v = int(num, 2)
				if v <= b:
					ans.append(v)
				else:
					break
	print(ans[-1])


n = int(input())
for k in range(n):
	(l, r) = map(int, input().split())
	a = []
	for i in range(62):
		a.append('0')
	lbin = list(bin(l))
	lbin = lbin[2:]
	ans = l
	num = l
	for i in range(len(lbin)):
		a[61 - i] = lbin[len(lbin) - 1 - i]
	blah = 0
	for i in range(61, -1, -1):
		if a[i] == '0':
			a[i] = '1'
			num = num + 2 ** (61 - i)
			if num <= r:
				ans = num
			else:
				break
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	b = bin(b)[2:]
	a = bin(a)[2:].zfill(len(b))
	for i in range(len(b)):
		if b[i] == '1' and a[i] == '0':
			break
	if a == b:
		print(int(a, 2))
	elif int(b[:i] + '1' + '1' * (len(b) - i - 1), 2) == int(b, 2):
		print(int(b[:i] + '1' + '1' * (len(b) - i - 1), 2))
	else:
		print(int(b[:i] + '0' + '1' * (len(b) - i - 1), 2))


def pops(k):
	ans = 0
	while k > 0:
		if k & 1:
			ans += 1
		k >>= 1
	return ans
for _ in range(int(input())):
	(l, r) = list(map(int, input().split()))
	i = 0
	while l | 1 << i <= r:
		l |= 1 << i
		i += 1
	print(l)


def f():
	(l, r) = map(int, input().split())
	if l == r:
		return l
	(a, b) = (bin(l)[2:], bin(r)[2:])
	(i, k) = (0, len(b))
	a = a.zfill(k)
	while a[i] == b[i]:
		i += 1
	d = k - i
	if b[i:].count('1') == d:
		return r
	return (r >> d << d) + (1 << d - 1) - 1
for i in range(int(input())):
	print(f())


from sys import stdin
from collections import defaultdict
import math

def countSetBits(n):
	count = 0
	while n:
		n &= n - 1
		count += 1
	return count

def brute(l, r):
	num = 0
	tim = 0
	for i in range(l, r + 1):
		if countSetBits(i) > tim:
			tim = countSetBits(i)
			num = i
	return num
mod = 10 ** 9 + 7
I = stdin.readline
t = int(I())
for _ in range(t):
	(l, r) = map(int, I().split())
	b1 = bin(l)[2:]
	b2 = bin(r)[2:]
	y = math.log(r + 1, 2)
	if r == 576460752303423487:
		ans = r
	elif len(b2) > len(b1):
		if y == int(y):
			ans = r
		else:
			x = len(b2)
			ans = 2 ** (x - 1) - 1
	else:
		n = len(b1)
		ans = []
		flag = 0
		if y == int(y):
			ans = r
		else:
			for i in range(n):
				if flag == 0:
					if b1[i] == b2[i]:
						ans.append(b1[i])
					elif b1[i] == '0' and b2[i] == '1':
						if i != n - 1:
							ans.append('0')
							flag = 1
						else:
							ans.append('1')
				else:
					ans.append('1')
			s = ''.join(ans)
			ans = int(s, 2)
			if countSetBits(r) > countSetBits(ans):
				ans = r
	print(ans)


import sys, os, io
from sys import stdin
import math
from collections import defaultdict
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
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')
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

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 primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

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

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

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

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def hasbit(x, bit):
	return x & 1 << bit

def solve():
	(l, r) = li()
	bit = 62
	ans = 0
	ans = ['0'] * 62
	while bit >= 0:
		if hasbit(l, bit) == hasbit(r, bit):
			if hasbit(l, bit) != 0:
				ans[bit] = '1'
		else:
			for j in range(bit - 1, -1, -1):
				ans[j] = '1'
			break
		bit -= 1
	ans = int(''.join(ans[::-1]), 2)
	if bin(r).count('1') > bin(ans).count('1'):
		print(r)
		return
	print(ans)
t = 1
t = ii()
for _ in range(t):
	solve()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	m = a
	bits = str(a).count('1')
	x = 0
	while a <= b:
		a |= 1 << x
		z = bin(a).count('1')
		if z > bits and a <= b:
			m = a
			bits = z
		elif z == bits and a < m:
			m = a
		x += 1
	print(m)


def ones(n):
	return bin(n).count('1')

def binary(n):
	return bin(n)[2:]
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	L = binary(l)
	R = binary(r)
	L = '0' * (len(R) - len(L)) + L
	idx = len(R)
	ans = ''
	for i in range(len(R)):
		if L[i] != R[i]:
			ans += L[i]
			idx = i
			break
		else:
			ans += L[i]
	ans += '1' * (len(R) - len(ans))
	can = int(ans, 2)
	if ones(r) > ones(can):
		print(r)
	else:
		print(can)


import sys
n = int(input())
for x in range(n):
	(l, r) = map(int, input().split())
	a = 0
	while l <= r:
		a = l
		l += ~l & -~l
	sys.stdout.write(str(a) + '\n')


for i in range(int(input())):
	(l, r) = map(int, input().split())
	k = 0 if l == r else len(bin(l ^ r)) - 2
	s = ((r >> k) + 1 << k) - 1
	if s > r:
		s -= 1 << k - 1
	print(s)


n = int(input())
for i in range(n):
	(l, r) = [int(k) for k in input().split()]
	(a, b) = (bin(r)[2:], bin(l)[2:])
	res = ''
	while True:
		if '0' not in a:
			res += a
			break
		if len(a) > len(b):
			res += '0'
			res += '1' * (len(a) - 1)
			break
		if a == b:
			res += a
			break
		res += a[0]
		a = a[1:]
		b = b[1:]
		while a[0] == '0' and b[0] == '0':
			res += '0'
			a = a[1:]
			b = b[1:]
		b = b.lstrip('0')
		if not b:
			b = '0'
	print(int(res, 2))


import sys
L = lambda x: len(bin(x)) - 2
n = int(input())
while n > 0:
	n -= 1
	(l, r) = map(int, sys.stdin.readline().split())
	a = 0
	while L(l) == L(r) and r > 0:
		u = 1 << L(r) - 1
		l -= u
		r -= u
		a += u
	u = 1 << L(r) - 1
	if u + u - 1 == r and r > 1:
		u <<= 1
	print(a + u - 1)


q = int(input())
for i in range(q):
	(x, y) = map(int, input().split())
	diff = y - x
	x = bin(x)[2:]
	y = bin(y)[2:]
	x = '0' * (len(y) - len(x)) + x
	newString = ''
	for j in range(len(x)):
		if x[len(x) - j - 1] == '0':
			if diff >= 2 ** j:
				newString += '1'
				diff -= 2 ** j
			else:
				newString += '0'
		else:
			newString += '1'
	newString = newString[::-1]
	tot = 0
	ns = len(newString)
	for i in range(ns):
		tot += int(newString[ns - i - 1]) * 2 ** i
	print(tot)


def popcount(n):
	res = 0
	while n > 0:
		res += n & 1
		n >>= 2

def A(l, r):
	r += 1
	t = 1 << 64
	while t & (l ^ r) == 0:
		t >>= 1
	res = l | t - 1
	return res
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	res = A(l, r)
	print(res)


n = int(input())
get = lambda x, i: x >> i & 1
for i in range(n):
	(l, r) = map(int, input().split())
	res = 0
	for i in range(63, -1, -1):
		res |= get(r, i) << i
		if get(l, i) != get(r, i):
			res -= 1
			if res ^ r == 1 << i:
				res = r
			break
	print(res)


from sys import stdin, stdout
from math import ceil
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
p2 = [1]
for i in range(1, 64):
	p2 += [p2[-1] * 2]
for _ in range(nmbr()):
	(l, r) = lst()
	sets = [0] * 64
	for bp in range(64):
		if r >> bp & 1:
			sets[bp] = 1 + sets[max(bp - 1, 0)]
		else:
			sets[bp] = sets[max(bp - 1, 0)]
	mx = sets[-1]
	init = mx
	ans = r
	for bp in range(64):
		if r >> bp & 1:
			new = r ^ p2[bp] | p2[bp] - 1
			if new >= l:
				bits = sets[-1] - sets[bp] + bp
				if bits > mx or (bits == mx and new < ans):
					ans = new
					mx = bits
	print(ans)


def parr(arr):
	print(*arr, sep=' ')

def gcd(a, b):
	while b:
		if b % a == 0:
			break
		tmp = a
		a = b % a
		b = tmp
	return a
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	i = 0
	while l | 1 << i <= r:
		l |= 1 << i
		i += 1
	print(l)


n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	l = bin(l)[2:]
	r = bin(r)[2:]
	while len(l) < len(r):
		l = '0' + l
	x = [0] * len(l)
	for i in range(len(l)):
		x[i] = l[i]
		if l[i] < r[i]:
			ok = True
			for j in range(i + 1, len(l)):
				x[j] = '1'
				if r[j] == '0':
					ok = False
			if ok:
				x[i] = '1'
			break
	print(int(''.join(x), 2))


def add_beginning_bits(nr, limit):
	mask = 1
	while nr + mask <= limit:
		if mask & nr == 0:
			nr |= mask
		mask <<= 1
	return nr
n = int(input())
for i in range(n):
	(left, right) = [int(x) for x in input().strip().split()]
	print(add_beginning_bits(left, right))


from math import pow
t = int(input())
while t > 0:
	(a, b) = [int(i) for i in input().split()]
	b1 = bin(b).lstrip('0b')
	a1 = bin(a).lstrip('0b')
	l1 = len(a1)
	l2 = len(b1)
	if l2 == b1.count('1'):
		print(b)
	elif a == b:
		print(b)
	else:
		a1 = list(a1)
		i = l1 - 1
		while i >= 0:
			if a1[i] == '0':
				a1[i] = '1'
				if int(''.join(a1), 2) <= b:
					continue
				else:
					a1[i] = '0'
					break
			i -= 1
		ans1 = 0
		if a1:
			ans1 = int(''.join(a1), 2)
		ans2 = int(pow(2, l2 - 1)) - 1
		if ans2 >= ans1:
			print(ans2)
		else:
			print(int(ans1))
	t -= 1


k = int(input())
for x in range(k):
	(l, r) = map(int, input().split())
	while l | l + 1 <= r:
		l |= l + 1
	print(l)


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import List, Mapping
sys.setrecursionlimit(999999)
p = [0, 1]
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	while p[-1] < r:
		p.append(p[-1] * 2 + 1)
	ans = 0
	while l < r:
		j = bisect.bisect_left(p, r + 1)
		j -= 1
		if l <= p[j] <= r:
			ans += p[j]
			r = l - 1
		else:
			ans += p[j] + 1
			l = l - p[j] - 1
			r = r - p[j] - 1
	if l == r:
		ans += l
	print(ans)


import math

def f(l, r):
	if l == r:
		return l
	else:
		b = int(math.log(r, 2))
		if p[b] <= l:
			return f(l - p[b], r - p[b]) + p[b]
		elif p[b + 1] - 1 <= r:
			return p[b + 1] - 1
		else:
			return p[b] - 1
p = [1]
for i in range(64):
	p.append(p[-1] * 2)
n = int(input())
for i in range(n):
	(l, r) = [int(i) for i in input().split()]
	print(f(l, r))


import math
import sys
n = int(sys.stdin.readline())

def f(l, r):
	if l == r:
		return l
	t = int(math.log2(r))
	if 2 ** t <= l:
		return f(l - 2 ** t, r - 2 ** t) + 2 ** t
	elif 2 ** (t + 1) - 1 <= r:
		return 2 ** (t + 1) - 1
	else:
		return 2 ** t - 1
ans = []
for _ in range(n):
	(l, r) = sys.stdin.readline().split()
	l = int(l)
	r = int(r)
	ans.append(f(l, r))
sys.stdout.write('\n'.join([str(el) for el in ans]))


def maxi(a, b):
	if bin(a).count('1') == bin(b).count('1'):
		return min(a, b)
	elif bin(a).count('1') > bin(b).count('1'):
		return a
	else:
		return b
t = int(input().rstrip())
for i in range(t):
	(a, b) = list(map(int, input().rstrip().split(' ')))
	x = bin(a)[2:]
	y = bin(b)[2:]
	w = max(len(x), len(y))
	x = '0' * (w - len(x)) + x
	y = '0' * (w - len(y)) + y
	q = [0 for i in range(w)]
	for j in range(w):
		if x[j] != y[j]:
			q[j] = '0'
			break
		else:
			q[j] = x[j]
	for o in range(j + 1, w):
		q[o] = '1'
	e = int('0b' + ''.join(q), 2)
	print(maxi(e, b))


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')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def ctd(chr):
	return ord(chr) - ord('a')
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		(l, r) = RL()
		bl = int(r).bit_length()
		res = 0
		for i in range(bl - 1, -1, -1):
			nb = 1 << i
			if l & nb == r & nb:
				if l & nb == nb:
					res += nb
			else:
				res += (1 << i) - 1
				if '0' not in bin(r)[-i - 1:]:
					res += 1 << i
				break
		print(res)
main()


def add_one(st):
	st = list(st)
	f = False
	for i in range(len(st) - 1, -1, -1):
		if st[i] == '0':
			st[i] = '1'
			f = True
			break
	if f == False:
		st.insert(0, '1')
	j = int(''.join(st), 2)
	if j <= y:
		p.append(j)
		add_one(st)
	else:
		print(p[-1])
p = []
a = 1
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	X = bin(x)[2:]
	p.append(x)
	add_one(X)


def get_near_power_of_two(x):
	b = 1
	while b <= x:
		b <<= 1
	return b >> 1
n = int(input())
for _ in range(n):
	(l, r) = list(map(int, input().split()))
	xor = l ^ r
	d = get_near_power_of_two(xor) - (0 if xor == 0 else 1)
	ld = l | d
	rd = r | d
	print(rd if rd == r else ld)


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

def popcnt(n):
	cnt = 0
	for i in range(len(n)):
		if n[i] == 1:
			cnt += 1
	return cnt
for _ in range(int(ri())):
	(a, b) = Ri()
	arra = solve(a)
	arrb = solve(b)
	if len(arra) != len(arrb):
		ans = len(arrb) - 1
		if popcnt(arrb) > ans:
			print(b)
		else:
			ans = (1 << len(arrb) - 1) - 1
			print(ans)
	else:
		ind = -1
		ans = 0
		flag = False
		temp = 0
		for i in range(len(arrb) - 1, -1, -1):
			if flag:
				ans = ans + 2 ** i
				temp += 1
				continue
			if arrb[i] != arra[i]:
				flag = True
			elif arrb[i] == 1:
				ans += 2 ** i
				temp += 1
		if popcnt(arrb) > temp:
			print(b)
		else:
			print(ans)


from math import ceil
from math import floor
from math import sqrt
from math import 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 find_least_diff(n):
	A = 2 * (pow(2, n / 2 - 1) - 1)
	B = -pow(2, n / 2)
	return int(abs(B - A))

def find_ways(n):
	return (n - 1) // 2

def count_digits(n):
	m = 9
	count = n
	while True:
		if n >= m:
			count += n - m
		else:
			break
		m = str(m)
		m += '9'
		m = int(m)
	return count

def kth_bit_set(n, k):
	return n & 1 << k - 1

def sum_is_zero(n, arr):
	for i in range(pow(2, n)):
		angle_sum = 0
		for j in range(n):
			if kth_bit_set(i, j + 1):
				angle_sum += arr[j]
			else:
				angle_sum -= arr[j]
		if angle_sum % 360 == 0:
			return True
	return False

def get_board(n, m, mat):
	for i in range(n):
		for j in range(m):
			print(i, j)
			if mat[i][j] == '.':
				if (j > 0 and mat[i][j - 1] != 'B') and (i > 0 and mat[i - 1][j] != 'B'):
					mat[i][j] = 'B'
				else:
					mat[i][j] = 'W'
	for i in range(n):
		for j in range(m):
			print(mat[i][j])

def check_and_print_pyth_triplets(n):
	if n <= 2:
		print(-1)
	elif n % 2 == 0:
		temp = n * n
		m = temp / 4 - 1
		k = temp / 4 + 1
		print(str(m), str(k))
	else:
		temp = n * n
		m = (temp - 1) / 2
		k = (temp + 1) / 2
		print(str(m), str(k))

def find_max_bit_set(L, R):
	if L == R:
		return L
	b = log(R) // log(2)
	val = int(pow(2, b + 1) - 1)
	m = int(pow(2, b))
	if L >= m:
		return find_max_bit_set(L - m, R - m) + m
	elif val <= R:
		return val
	return m - 1

def there_is_a_way(n, pipes):
	row = 0
	for c in range(0, n):
		if pipes[c][row] <= 2:
			continue
		else:
			nxt_row = (row + 1) % 2
			if pipes[c][nxt_row] > 2:
				row = nxt_row
			else:
				return false
	return row == 1

def contest_function(n, arr):
	count = 1
	i = n - 1
	mx = 0
	while i > 0:
		if arr[i] <= 2 * arr[i - 1]:
			count += 1
		else:
			mx = max(mx, count)
			count = 1
		i -= 1
	return mx

def fun(y):
	return 1 / 3 * (1 / sqrt(1 + y * y) + 1 / sqrt(25 + y * y) + 4 * (1 / sqrt(1 + 4 * y * y) + 1 / sqrt(1 + 16 * y * y)) + 2 * 1 / sqrt(1 + 9 * y * y))
t = 1
t = int(input())
while t:
	t = t - 1
	count = 0
	(L, R) = map(int, input().split())
	print(int(find_max_bit_set(L, R)))


import math

def func(a, b):
	n = a
	m = b
	n = n | n >> 1
	n = n | n >> 2
	n = n | n >> 4
	n = n | n >> 8
	n = n | n >> 16
	n = n | n >> 32
	n = n | n >> 64
	t = n + 1 >> 1
	if t <= b:
		return func(a - t, b - t) + t
	elif 2 * t - 1 == a:
		return 2 * t - 1
	else:
		return t - 1
t = int(input())
for j in range(t):
	arr = input().split()
	n = max(int(arr[0]), int(arr[1]))
	m = min(int(arr[0]), int(arr[1]))
	if m == n:
		print(m)
	elif n - 1 == m:
		cnt1 = 0
		cnt2 = 0
		a = n
		b = m
		while a:
			a = a & a - 1
			cnt1 += 1
		while b:
			b = b & b - 1
			cnt2 += 1
		if cnt2 >= cnt1:
			print(m)
		else:
			print(n)
	else:
		print(func(n, m))


n = int(input())
for i in range(n):
	x = [bin(int(i))[2:] for i in input().split()]
	l = x[0]
	r = x[1]
	if len(l) != len(r):
		if '1' * len(r) == r:
			print(int(r, 2))
		else:
			print(int('1' * (len(r) - 1), 2))
	else:
		j = 0
		while j < len(r) and l[j] == r[j]:
			j += 1
		if '1' * len(r[j:]) == r[j:]:
			print(int(r, 2))
		else:
			print(int(r[:j] + '0' + '1' * (len(r[j:]) - 1), 2))


n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	ans = l
	for i in range(65):
		if ans & 1 << i == 0:
			if ans + (1 << i) <= r:
				ans = ans + (1 << i)
	print(ans)


def BinToDec(s):
	n = len(s)
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += int(s[i]) * 2 ** (n - i - 1)
	return ans
t = int(input(''))
cnt = 0
for _ in range(t):
	[l, r] = list(map(int, input().split()))
	sl = bin(l)
	sr = bin(r)
	if l == r:
		print(l)
	elif len(sl) != len(sr):
		n = len(sr) - 2
		if r == 2 ** n - 1:
			print(r)
		else:
			print(-1 + 2 ** (n - 1))
	else:
		sr = list(sr[2:])
		sl = list(sl[2:])
		n = len(sr)
		if r == 2 ** n - 1:
			print(r)
			continue
		k = n - 1
		for i in range(n):
			if sl[i] == '0' and sr[i] == '1':
				k = i
				break
		if k == n - 1:
			print(r)
			continue
		sign = 1
		for i in range(k + 1, n):
			if sr[i] == '0':
				sign = 0
				break
		if sign:
			print(r)
			continue
		for j in range(k + 1, n):
			sl[j] = '1'
		print(BinToDec(sl))


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	(left, right) = sp()
	answer = left
	for i in range(65):
		if not left & 1 << i and answer + (1 << i) <= right:
			answer += 1 << i
	out(answer)


def countMaxSetBits(left, right):
	while left | left + 1 <= right:
		left |= left + 1
	return left
for _ in range(int(input())):
	(l, r) = map(int, input().split())
	print(countMaxSetBits(l, r))


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, 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()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
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('a')

def solve():
	for _ in range(ii()):
		(l, r) = mi()
		x = 0
		f = 0
		for i in range(63, -1, -1):
			if l >> i & 1 and r >> i & 1:
				x |= 1 << i
			elif r >> i & 1:
				x |= (1 << i) - 1
				i += 1
				x1 = x | (1 << i) - 1
				if x1 <= r:
					print(x1)
				else:
					print(x)
				f = 1
				break
		if f == 0:
			print(x)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


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())
MOD = 10 ** 9 + 7
all_ones = set()
i = 2
while True:
	all_ones.add(i - 1)
	i *= 2
	if i > 10 ** 18:
		break

def bits(x):
	return list(bin(x)[2:])

def solve():
	(L, R) = getInts()
	if L == R:
		return L
	if R in all_ones:
		return R
	(ll, rr) = (bits(L), bits(R))
	if len(ll) < len(rr):
		return pow(2, len(rr) - 1) - 1
	idx = 0
	while ll[idx] == rr[idx]:
		idx += 1
	if rr[idx:] == ['1'] * (len(rr) - idx):
		return R
	return int(''.join(ll[:idx + 1] + ['1'] * (len(ll) - idx - 1)), 2)
for _ in range(getInt()):
	print(solve())


for u in range(int(input())):
	(x, y) = map(int, input().split())
	while x | x + 1 <= y:
		x |= x + 1
	print(x)


T = int(input())
lis = []
for i in range(100):
	lis.append(2 ** i - 1)
for kase in range(T):
	(l, r) = [int(x) for x in input().split()]
	(x, y) = (l, r)
	if l == r:
		print(l)
		continue
	i = 100
	while True:
		if l & 2 ** i == r & 2 ** i:
			if l & 2 ** i:
				l -= 2 ** i
				r -= 2 ** i
		else:
			break
		i -= 1
	if r in lis:
		print(r | y)
	else:
		print(y - 2 ** i | 2 ** i - 1)


import sys
input = sys.stdin.readline

def IN():
	return int(input())

def INL():
	return map(int, input().split())
for _ in range(IN()):
	(l, r) = INL()
	arr = []
	i = 0
	for i in range(63):
		if l > r:
			break
		sol = l
		l |= 1 << i
	print(sol)


def bin(s):
	s = int(s)
	ans = ''
	cnt = 0
	while s > 0:
		ans += str(s % 2)
		cnt += int(s % 2)
		s = s // 2
	return ((61 - len(ans)) * '0' + ans[::-1], cnt)

def dec(s):
	s = str(s)
	(n, fac) = (0, 1)
	for i in reversed(range(len(s))):
		n += int(s[i]) * fac
		fac *= 2
	return n

def cntzero(s):
	s = str(s)
	ans = 0
	for i in s:
		if i == '1':
			ans += 1
	return ans
q = int(input())
while q > 0:
	q -= 1
	(a, b) = list(map(int, input().split()))
	if a == b:
		print(a)
		continue
	(A, cntA) = bin(a)
	(B, cntB) = bin(b)
	for i in range(61):
		if A[i] == '0' and B[i] == '1':
			s1 = A[:i + 1] + '1' * (60 - i)
			if cntB > cntzero(s1):
				print(b)
			else:
				print(dec(s1))
			break


n = int(input())

def count(num):
	ct = 0
	for i in range(len(num)):
		if num[i:i + 1] == '1':
			ct += 1
	return ct
for i in range(n):
	line = input().split()
	a = int(line[0])
	b = int(line[1])
	if a == b:
		print(a)
		continue
	l = bin(a)[2:]
	u = bin(b)[2:]
	while len(l) < 60:
		l = '0' + l
	while len(u) < 60:
		u = '0' + u
	start = '1' * 60
	end = ''
	for j in range(59):
		charL = l[j:j + 1]
		charU = u[j:j + 1]
		if charL == charU and charL == '0':
			end += '0'
			continue
		if charL != charU:
			end += '0' + start[j + 1:]
			break
		end += '1'
	if count(u) > count(end):
		print(b)
	else:
		print(int(end, 2))


t = int(input())
for test in range(t):
	(l, r) = map(int, input().split())
	bl = bin(r)[2:]
	br = bin(l)[2:]
	br = '0' * (len(bl) - len(br)) + br
	mx = bl.count('1')
	mxm = bl
	for i in range(len(bl)):
		if bl[i] != br[i]:
			temp = len(bl) - i - 1 + bl[0:i].count('1')
			if temp >= mx:
				mx = temp
				mxm = bl[0:i] + '0' + '1' * (len(bl) - i - 1)
				break
	print(int(mxm, 2))


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left
mod = 998244353
mod = 1000000007

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b

def moduloinverse(a):
	return pow(a, mod - 2, mod)

def solve(we):
	(a, b) = main()
	ab = bin(a)[2:]
	bb = bin(b)[2:]
	if len(ab) < len(bb):
		x = int('1' * len(bb), 2)
		y = int('1' * (len(bb) - 1), 2)
		if x <= b:
			print(x)
		else:
			print(y)
	else:
		ans = ''
		t = len(ab)
		for i in range(len(ab)):
			t -= 1
			if bb[i] == ab[i]:
				ans += bb[i]
			elif i == len(ab) - 1:
				ans += bb[i]
			else:
				ans += '0' + '1' * t
				break
		if ans.count('1') >= bb.count('1'):
			print(int(ans, 2))
		else:
			print(b)
qwe = 1
qwe = iin()
for _ in range(qwe):
	solve(_ + 1)


x = int(input())
for i in range(x):
	x1 = str(input()).split()
	left = int(x1[0])
	right = int(x1[1])
	while left | left + 1 <= right:
		left |= left + 1
	print(left)


import sys
import math
import collections
import heapq
input = sys.stdin.readline
n = int(input())
for i in range(n):
	(l, r) = (int(i) for i in input().split())
	while l | l + 1 <= r:
		l |= l + 1
	print(l)


n = int(input())
for kase in range(n):
	(l, r) = map(int, input().split())
	bit = 0
	while l | 1 << bit <= r:
		l = l | 1 << bit
		bit += 1
	print(l)


n = int(input())

def po(x):
	p = 2
	i = 1
	while p <= x:
		i += 1
		p *= 2
	return i - 1

def f(l, r):
	b = po(r)
	q = 2 ** b
	if l == r:
		return l
	elif q <= l:
		return f(l - q, r - q) + q
	elif q * 2 - 1 <= r:
		return q * 2 - 1
	else:
		return q - 1
for i in range(n):
	(l, r) = map(int, input().split())
	print(f(l, r))


import sys
from math import gcd, sqrt, ceil, log2
from collections import defaultdict, Counter, deque
from bisect import bisect_left, bisect_right
import math
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 debug(l, r):
	maxi = -1
	ans = -1
	for i in range(l, r + 1):
		z = bin(i).count('1')
		if z > maxi:
			maxi = z
			ans = i
	return ans
ha = []
cnt = 0
while 2 ** cnt <= 10 ** 18:
	ha.append(2 ** cnt)
	cnt += 1
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	if l == r:
		print(l)
		continue
	z = int(log2(r))
	k = 2 ** z - 1
	if l <= k <= r:
		if bin(k)[2:].count('1') >= bin(r)[2:].count('1'):
			print(k)
		else:
			print(r)
	else:
		z1 = bin(l)[2:]
		z2 = bin(r)[2:]
		flag = 0
		ans = []
		for i in range(len(z1)):
			if flag == 1:
				ans.append('1' * (len(z1) - len(ans)))
				break
			else:
				if int(z2[i]) > int(z1[i]):
					flag = 1
				ans.append(z1[i])
		z = int(''.join(ans), 2)
		if bin(z)[2:].count('1') >= bin(r)[2:].count('1'):
			print(z)
		else:
			print(r)


for _ in range(int(input())):
	(l, r) = map(int, input().split())
	i = 1
	while i <= r:
		tmp = l | i
		if tmp <= r:
			l = tmp
		i = i << 1
	print(l)