Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.

The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!

A xor-sum of a sequence of integers a_1, a_2, ..., a_{m} is defined as the bitwise XOR of all its elements: $a_{1} \oplus a_{2} \oplus \ldots \oplus a_{m}$, here $\oplus$ denotes the bitwise XOR operation; more about bitwise XOR can be found here.

Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.


-----Input-----

The sole string contains two integers n and k (1 ≤ k ≤ n ≤ 10^18).


-----Output-----

Output one number — the largest possible xor-sum.


-----Examples-----
Input
4 3

Output
7

Input
6 6

Output
7



-----Note-----

In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.

In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.

Source: codeforces | Difficulty: EASY
Tags: Number theory

Bit manipulation

Constructive algorithms


Solutions:
(n, k) = map(int, input().split())
ans = []
i = 0
while True:
	if 2 ** i <= n:
		ans.append(i)
		i += 1
	else:
		break
aa = 0
if k == 1:
	print(n)
else:
	for i in range(len(ans)):
		aa += 2 ** ans[i]
	print(aa)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
	return
ans = 1
while 2 ** ans <= n:
	ans += 1
ans = 2 ** ans - 1
print(ans)


(n, k) = map(int, input().split(' '))
if k == 1:
	print(n)
else:
	num = 1
	while num <= n:
		num <<= 1
	print(num - 1)


(n, k) = (int(x) for x in input().split())
from math import *
if k == 1:
	print(n)
else:
	p = 0
	while n != 0:
		p += 1
		n //= 2
	print(2 ** p - 1)


import sys

def main():
	(n, m) = map(int, sys.stdin.readline().split())
	if m == 1:
		return n
	return (1 << n.bit_length()) - 1
print(main())


import sys
for line in sys.stdin:
	(n, k) = line.strip().split()
	(n, k) = (int(n), int(k))
	if k == 1:
		print(n)
		continue
	ans = 1
	while ans < n:
		ans = ans * 2 + 1
	print(ans)


(n, k) = map(int, input().split())
z = 1 << int.bit_length(n)
if k == 1:
	print(n)
else:
	print(z - 1)


(a, b) = map(int, input().split())
a = int(a)
b = int(b)
i = 1
if b == 1:
	print(a)
else:
	while i <= a:
		i *= 2
	print(i - 1)


(n, k) = map(int, input().split())
b = bin(n)[2:]
l = len(b)
bx = '1' * l
print(int(bx, 2)) if k > 1 else print(n)


import sys
(n, k) = map(int, sys.stdin.readline().split(' '))
if k <= 1:
	print(n)
	sys.exit(0)
else:
	ans = 1
	while ans < n:
		ans = ans * 2 + 1
print(ans)


(n, k) = map(int, input().split())
mx = 1
while 2 * mx <= n:
	mx *= 2
if k == 1:
	print(n)
else:
	print(mx ^ mx - 1)


def read():
	return map(int, input().split())
(n, k) = read()
if k == 1:
	answer = n
else:
	answer = 1
	while answer < n + 1:
		answer += answer
	answer -= 1
print(answer)


(x, y) = map(int, input().split())
if y > 0:
	if y == 1:
		print(x)
	else:
		s = str(bin(x))[2:]
		k = len(s) * '1'
		k = int(k, 2)
		print(k)


from math import *
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	x = 0
	while n > 1:
		x += 1
		n = n // 2
	x += 1
	print(2 ** x - 1)


(n, k) = map(int, input().split())
x = len(bin(n)) - 2
s = bin(n)[2:]
z = n
a = 0
if k == 1:
	print(n)
else:
	print(2 ** x - 1)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	print(2 ** len(bin(n)[2:]) - 1)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	c = 0
	while n != 0:
		n = n // 2
		c += 1
	print(pow(2, c) - 1)


(a, b) = map(int, input().split())
if b == 1:
	print(a)
else:
	ans = len(str(bin(a))) - 2
	print(2 ** ans - 1)


import sys
import math
import os
import re
(n, k) = map(int, input().split())
count = 0
t = n
while n != 0:
	count += 1
	n = n // 2
if k == 1:
	print(t)
else:
	sum = 1
	for i in range(0, count):
		sum = sum * 2
	print(sum - 1)


(n, k) = map(int, input().split())
powe = 0
st = 1
while st <= n:
	powe += 1
	st *= 2
if k >= powe:
	i = powe
	key = 1
else:
	i = k
	key = 0
ans = 0
if key == 1:
	print(st - 1)
elif k == 1:
	print(n)
else:
	print(st - 1)


(n, k) = map(int, input().split())
a = 1
for i in range(n):
	if a * 2 > n:
		a *= 2
		break
	a *= 2
if k == 1:
	print(n)
else:
	print(a - 1)


R = lambda : map(int, input().split())
(n, k) = R()
if k == 1:
	print(n)
else:
	i = 0
	while 1 << i <= n:
		i += 1
	print((1 << i) - 1)


(n, k) = list(map(int, input().split()))
r = 0
nn = n
while nn:
	nn >>= 1
	r += 1
print((1 << r) - 1 if k > 1 else n)


(n, k) = [int(x) for x in input().split()]
if k == 1:
	print(n)
	return
a = 1
s = 0
while a <= n:
	s += a
	a *= 2
print(s)


(n, k) = map(int, input().split())
len = 0
sum = 0
t = n
while n > 0:
	n = n // 2
	len += 1
p = 1
for i in range(0, len):
	sum += p
	p *= 2
if k > 1:
	print(sum)
else:
	print(t)


(n, k) = input().split()
n = int(n)
k = int(k)
if k == 1:
	print(n)
else:
	p = 0
	while n != 0:
		n //= 2
		p += 1
	print(int(2 ** p - 1))


(n, k) = map(int, input().split())
num = n
cnt = 0
while n != 0:
	cnt += 1
	n //= 2
ans = (1 << cnt) - 1
if k == 1:
	print(num)
else:
	print(ans)


def comp(a):
	c = bin(a)
	ans = ''
	for i in c[2:]:
		if i == '0':
			ans += '1'
		else:
			ans += '0'
	return int(ans, 2)
(n, k) = map(int, input().split())
if k > 1:
	print(n ^ comp(n))
else:
	print(n)


from math import log2, floor
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	p = len(bin(n)) - 2
	print(2 ** p - 1)


(n, k) = (int(x) for x in input().split())
s = '{0:b}'.format(n)
if k == 1:
	print(n)
else:
	ans = ''
	for c in s:
		if c == '0':
			c = '1'
		ans += c
	print(int(ans, 2))


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	print(int(n.bit_length() * '1', 2))


def STR():
	return list(input())

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

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

def MAP2():
	return map(float, input().split())

def LIST():
	return list(map(int, input().split()))

def STRING():
	return input()
import string
import sys
from heapq import heappop, heappush
from bisect import *
from collections import deque, Counter, defaultdict
from math import *
from itertools import permutations, accumulate
dx = [-1, 1, 0, 0]
dy = [0, 0, 1, -1]
(n, k) = MAP()
if k == 1:
	print(n)
else:
	l = len(bin(n)) - 2
	ans = 1 << l
	print(ans - 1)


import math
(n, k) = map(int, input().split())
x = str(bin(n))
x = x[2:]
t = '1'
for i in range(len(x)):
	if i:
		t = t + '0'
a = int(t, 2)
print(2 * a - 1 if k > 1 else n)


(a, b) = map(int, input().split())
l = [2 ** i for i in range(1, 100)]
t = 0
for i in l:
	if a < i:
		t = i
		break
if b == 1:
	print(a)
else:
	print(t - 1)


import sys
(n, k) = map(int, input().split())
if k == 1:
	print(n)
	sys.exit(0)
ans = 1
while ans < n:
	ans = ans * 2 + 1
print(ans)


def main():
	(n, k) = tuple(map(int, input().split()))
	if k == 1:
		print(n)
		return
	p = 0
	while n:
		n = n // 2
		p += 1
	print(2 ** p - 1)
main()


import math
(n, k) = input().split()
n = int(n)
k = int(k)
if k == 1:
	print(n)
else:
	val = 1
	while val <= n:
		val = val * 2
	val = val - 1
	print(val)


s = input().split()
n = int(s[0])
k = int(s[1])
t = 0
res = 0
while 2 ** t <= n:
	t += 1
if k == 1:
	res = n
else:
	res = 0
	i = 0
	while i < t:
		res += 2 ** i
		i += 1
print(res)


import atexit
import io
import sys
import os
from bisect import *
from collections import *
from fractions import gcd
from fractions import Fraction as fr_
from itertools import *
import math
inf = float('inf')
inf_neg = float('-inf')
range_6 = int(10000000.0 + 1)
range_7 = int(1000000.0 + 1)
range_8 = int(100000000.0 + 1)
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
	(N, K) = map(int, input().split())
	if K == 1:
		print(N)
	else:
		for i in range(64):
			if N >> i & 1:
				ans = i
		ex = pow(2, ans + 1)
		print(ex - 1)
main()


(n, k) = map(int, input().split())
from math import log2
v = int(log2(n))
if 2 ** (v + 1) <= n:
	v += 1
if 2 ** v > n:
	v -= 1
if k == 1:
	print(n)
else:
	print(2 ** (v + 1) - 1)


(n, k) = (int(i) for i in input().split())
if k == 1:
	print(n)
else:
	ans = 0
	while n > 0:
		(n, ans) = (n >> 1, ans + 1)
	ans = (1 << ans) - 1
	print(ans)


(n, m) = map(int, input().split())
p = []
o = n
while n >= 2:
	p.append(n % 2)
	n = n // 2
p.append(n)
if m != 1:
	t = len(p)
	r = pow(2, t) - 1
	print(r)
else:
	print(o)


s = input().split()
(n, k) = (int(s[0]), int(s[1]))
if k == 1:
	print(n)
else:
	print(pow(2, len(bin(n)[2:])) - 1)


(n, k) = (int(x) for x in input().split())
if k == 1:
	print(n)
else:
	p = 0
	while n != 0:
		p += 1
		n //= 2
	print(2 ** p - 1)


def function(n):
	count = 0
	while n > 0:
		count += 1
		n = n >> 1
	return 1 << count
(n, k) = [int(i) for i in input().split()]
if k == 1:
	print(n)
else:
	p = function(n)
	print(p - 1)


import math
l = list(map(int, input().split(' ')))
n = l[0]
k = l[1]
s = bin(n)[2:]
lend = len(s)
su = 0
for i in range(len(s)):
	su = su + 2 ** i
if k == 1:
	print(n)
else:
	print(su)


(n, k) = map(int, input().strip().split())
ans = 1
counter = 1
if k == 1:
	ans = n
else:
	while ans < n:
		ans = counter * 2 + ans
		counter <<= 1
print(ans)


inp = input().split(' ')
largestnum = int(inp[0])
trash = int(inp[1])
if trash == 1:
	print(largestnum)
else:
	res = largestnum
	k = 0
	while 2 ** k <= largestnum:
		k = k + 1
	print(2 ** k - 1)


(a, b) = map(int, input().split())
s = 0
from math import *
k = floor(log2(a))
if b == 1 or bin(a).count('0') == 1:
	exit(print(a))
while k >= 0 and b > 0:
	s += 1 << k
	b -= 1
	k -= 1
	if b == 1:
		while k > -1:
			s += 1 << k
			k -= 1
			b -= 1
print(s)


(p, m) = map(int, input().split())
s = bin(p)
s = s[2:]
n = len(s)
ans = pow(2, n) - 1
if m >= 2:
	print(ans)
else:
	print(p)


read = lambda : map(int, input().split())
(n, k) = read()
c = 1
while c * 2 <= n:
	c <<= 1
ans = 0
if k > 1:
	ans = c * 2 - 1
else:
	ans = n
print(ans)


[n, k] = list(map(int, input().split()))
s = 1
cnt = 0
if k == 1:
	print(n)
else:
	while s <= n:
		s <<= 1
		cnt += 1
	print((1 << cnt) - 1)


(n, k) = list(map(int, input().split()))
binary = list(bin(n)[2:])
if k > 1:
	print(int(''.join(['1' for i in range(len(binary))]), 2))
elif k == 1:
	print(n)


[n, k] = list(map(int, input().split()))
x = bin(n)
x = list(x[2:])
m = len(x)
if k == 1:
	print(n)
else:
	print(2 ** m - 1)


import sys

def inp():
	return sys.stdin.readline().strip()
(n, k) = map(int, inp().split())
ans = []
i = 0
j = 0
if k == 1:
	print(n)
else:
	while i <= n:
		i = 1 << j
		if i <= n:
			ans.append(1 << j)
		j += 1
	ans.reverse()
	answer = 0
	for item in ans:
		answer ^= item
	print(answer)


import math
(x1, x2) = map(int, input().split(' '))
num = bin(x1)
dig = 0
dig = len(num) - 2
if x2 == 1:
	print(x1)
else:
	print(int(math.pow(2, dig)) - 1)


t = 1
for _ in range(t):
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	else:
		ans = 1
		while n:
			ans *= 2
			n = n // 2
		print(ans - 1)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
	quit()
ans = 1
while ans < n:
	ans = ans << 1
	ans = ans | 1
print(ans)


from math import log2, ceil
(n, k) = map(int, input().split())
ln = len(bin(n)) - 2
if k == 1:
	print(n)
else:
	print(2 ** ln - 1)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit()
ans = 1
while ans < n:
	ans = ans * 2 + 1
print(ans)


import math
(x1, x2) = map(int, input().split())
j = x1
t = 0
f = bin(x1)
t = len(f) - 2
if x2 == 1:
	print(j)
else:
	print(int(math.pow(2, t)) - 1)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	(count, x) = (1, 1)
	while x < n:
		x = pow(2, count) + x
		count += 1
	print(x)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	k = 0
	while n > 0:
		n = n >> 1
		k += 1
	print((1 << k) - 1)


(a, b) = list(map(int, input().split()))
shift = 1
cnt = 0
while shift <= a:
	shift <<= 1
	cnt += 1
ans = 0
if b == 1:
	ans = a
elif cnt >= b:
	while shift > 0:
		shift >>= 1
		ans += shift
else:
	while shift > 0 and b > 0:
		shift >>= 1
		ans += shift
		b -= 1
print(ans)


(n, k) = map(int, input().split())
temp = n
bit = 0
while temp:
	bit += 1
	temp = temp >> 1
if k == 1:
	print(n)
else:
	print(2 ** bit - 1)


import sys
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	ans = 1
	while ans < n:
		ans = ans * 2 + 1
	print(ans)


(N, K) = (int(i) for i in input().split())
if K == 1:
	print(N)
else:
	print(2 ** N.bit_length() - 1)


(n, k) = input().split()
n = int(n)
k = int(k)
if k == 1:
	print(n)
else:
	i = 0
	while 1 << i <= n:
		i = i + 1
	i = i - 1
	a = 1 << i
	b = a - 1
	ans = a ^ b
	print(ans)


import math
(n, k) = list(map(int, input().split()))
if k == 1:
	print(n)
else:
	print(int(math.pow(2, len(bin(n)) - 2)) - 1)


(n, k) = list(map(int, input().split()))
if k == 1:
	print(n)
else:
	i = 1
	while i <= n:
		i *= 2
	print(i - 1)


def main():
	l = input().split()
	l[0] = int(l[0])
	l[1] = int(l[1])
	n = l[0]
	k = l[1]
	if k == 1:
		print(n)
	else:
		ans = 1
		while ans <= n:
			ans <<= 1
		print(ans - 1)
main()


(n, k) = [int(i) for i in input().split()]
if k == 1:
	print(n)
else:
	print(2 ** (len(bin(n)) - 2) - 1)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit()
(t, m) = (n, 0)
while t > 0:
	t = t >> 1
	m += 1
print((1 << m) - 1)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	i = 0
	t = 1
	while t <= n:
		i += 1
		t *= 2
	print(t - 1)


import math
log2 = lambda x: math.log(x) / math.log(2)
(n, k) = map(int, input().split())
m = 2 ** int(log2(n))
res = 0
ans = m ^ m - 1
if k >= 2:
	print(n if ans > 2 * n else ans)
else:
	print(n)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	b = 1
	while n:
		b <<= 1
		n >>= 1
	print(b - 1)


def problemB():
	(n, k) = list(map(int, input().strip().split()))
	if k == 1:
		print(n)
	else:
		bas = 1
		while n > 0:
			n //= 2
			bas *= 2
		print(bas - 1)
problemB()


(n, k) = map(int, input().split())
a = len(bin(n).replace('0b', ''))
b = int('1' * a, 2)
if n < b:
	b = int('1' * (a - 1), 2)
if k == 1:
	print(n)
elif b == n:
	print(b)
else:
	print(b ^ b + 1)


(n, k) = map(int, input().split())
largestpow = 0
j = n
while j > 0:
	largestpow = largestpow + 1
	j = j // 2
if k == 1:
	print(n)
else:
	print(2 ** largestpow - 1)


R = lambda : list(map(int, input().split()))
(n, k) = R()
ans = -1

def solve():
	x = 1
	while x < n:
		x = x * 2 + 1
	return x
if k == 1:
	ans = n
else:
	ans = solve()
print(ans)


(a, b) = map(int, input().split())
if b == 1:
	print(a)
else:
	f = len(bin(a).replace('0b', ''))
	print((1 << f) - 1)


import sys
import itertools
import functools

def brute_exact(n, k):
	ar = list(range(1, n + 1))
	combinations = list(itertools.combinations(ar, k))
	if not combinations:
		return 0
	xor_conv = lambda ar: functools.reduce(lambda x, y: x ^ y, ar)
	return max([xor_conv(combination) for combination in combinations])

def brute_atleast(n, k):
	return max([brute_exact(n, i) for i in range(1, k + 1)])

def solve(n, k):
	if k == 1:
		return n
	return 2 ** n.bit_length() - 1

def main():
	(n, k) = list(map(int, input().split()))
	print(solve(n, k))

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	bs = len(str(bin(n))[2:])
	ans = sum([1 << i for i in range(bs)])
	print(ans)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	print(int(bin(n)[2:].replace('0', '1'), 2))


(n, k) = [int(i) for i in input().split()]
x = len(list(bin(n).replace('0b', '')))
m = 2 ** x - 1
if k >= 2:
	print(m)
else:
	print(n)


import sys, math
input = sys.stdin.readline
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	msb = len(bin(n)) - 2
	ans = 1 << msb
	print(ans - 1)


import math
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	ans = 0
	while n != 0:
		ans = ans * 2 + 1
		n = n >> 1
	print(ans)


X = list(map(int, input().split()))
if X[1] == 1:
	print(X[0])
else:
	Size = len(bin(X[0])) - 2
	print(int('1' * Size, 2))


import math
(n, k) = map(int, input().split())
(i, t) = (1, 0)
while i <= n:
	i *= 2
	t += 1
t -= 1
res = 2 ** (t + 1) - 1 if k >= 2 else n
print(res)


(n, k) = list(map(int, input().split()))
n0 = n
cnt = 0
while n0:
	n0 >>= 1
	cnt += 1
a = (1 << cnt) - 1
if k == 1:
	print(n)
else:
	print(a)


pin = lambda : map(int, input().split())
(x, a) = pin()
if a == 1:
	print(x)
	exit()
print(2 ** x.bit_length() - 1)


from math import log2
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	ans = 0
	i = 0
	while n:
		ans += 1 << i
		n //= 2
		i += 1
	print(ans)


import math
import sys
(n, k) = list(map(int, input().split()))
if k == 1:
	print(n)
	sys.exit(0)
for i in range(100):
	if 2 ** i <= n and 2 ** (i + 1) > n:
		x = i
		break
print(2 ** (x + 1) - 1)


def main():
	(n, k) = map(int, input().split(' '))
	if k == 1:
		print(n)
	else:
		s = bin(n)
		s1 = ''
		for i in range(s.__len__() - 2):
			s1 = s1 + '1'
		print(int(s1, 2))
main()


def pops(k):
	ans = 0
	while k > 0:
		if k & 1:
			ans += 1
		k >>= 1
	return ans

def bits(k):
	ans = 0
	while k > 0:
		ans += 1
		k >>= 1
	return ans
(n, k) = list(map(int, input().split()))
if k > 1:
	print((1 << bits(n)) - 1)
else:
	print(n)


[n, k] = [int(i) for i in input().split()]
if k == 1:
	print(n)
else:
	mx = 0
	while 2 ** mx <= n:
		mx += 1
	mx -= 1
	s = 0
	for i in range(mx, -1, -1):
		s += 2 ** i
	print(s)


import math as m
(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit(0)
temp = len(bin(n)[2:])
print(pow(2, temp) - 1)


(n, k) = map(int, input().split(' '))
x = 1
while x < n:
	x *= 2
if x > n:
	x //= 2
if k > 1:
	print(x + x - 1)
if k == 1:
	print(n)


import math
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	x = math.floor(math.log2(n)) + 1
	if 2 ** (x - 1) > n:
		print(2 ** (x - 1) - 1)
	else:
		print(2 ** x - 1)


from math import pow

def main():
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
	else:
		ans = 1
		while ans < n:
			ans = ans * 2 + 1
		print(ans)
main()


(n, k) = map(int, input().split())
if k == 1:
	exit(print(n))
t = 1
while t <= n:
	t *= 2
t -= 1
print(t)


(a, k) = map(int, input().split())
d = 0
if k == 1:
	exit(print(a))
while a > 0:
	d += 1
	a >>= 1
print((1 << d) - 1)


def ans(n, k):
	pow2 = 0
	tmp = n
	while tmp > 0:
		pow2 = 2 * pow2 + 1
		tmp = tmp // 2
	if k == 1:
		return n
	else:
		return pow2
(n, k) = [int(i) for i in input().split(' ')]
print(ans(n, k))


import sys
sys.setrecursionlimit(1000000)
read = sys.stdin.readline
(N, K) = map(int, read().split())
if K == 1:
	print(N)
	return
allOne = 1
while allOne << 1 <= N:
	allOne <<= 1
allOne <<= 1
allOne -= 1
print(allOne)


(n, k) = list(map(int, input().split()))
cnt = 0
if k == 1:
	print(n)
	return
while n:
	n //= 2
	cnt += 1
ans = 0
while cnt:
	ans += 2 ** (cnt - 1)
	cnt -= 1
print(ans)


(n, k) = map(int, input().split())
cnt = 0
if k == 1:
	print(n)
	exit(0)
while n:
	n //= 2
	cnt += 1
ans = 0
while cnt:
	ans += 2 ** (cnt - 1)
	cnt -= 1
print(ans)


import math
(n, k) = list(map(int, input().split()))
if k == 1:
	print(n)
else:
	x = 1
	while x < n:
		x = (x << 1) + 1
	print(x)


(n, k) = [int(i) for i in input().split()]

def f():
	for i in range(70):
		if pow(2, i) > n:
			x = i
			return x
i = f()
y = sum([pow(2, i - k - 1) for k in range(i)])
if k == 1:
	print(n)
else:
	print(y)


import sys, os
from math import sqrt, gcd, ceil, log, floor, sin, pi
from math import factorial as fact
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7

def f(n):
	c = -1
	while 2 ** (c + 1) <= n:
		c += 1
	return c

def main():
	(n, k) = read()
	if k == 1:
		print(n)
	else:
		print(2 ** (len(bin(n)) - 2) - 1)
main()


(n, k) = [int(x) for x in input().split()]
if k == 1:
	print(n)
else:
	ns = bin(n)[2:]
	ns = ns.replace('0', '1')
	print(int(ns, 2))


(n, k) = list(map(int, input().split()))
if k == 1:
	print(n)
else:
	bin_n = bin(n)[2:]
	max_deg = len(bin_n)
	print((1 << max_deg) - 1)


import math
(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit()
z = int(math.log2(n))
if 2 ** z > n:
	z -= 1
ans = 2 ** z
ans -= 1
if ans >= n:
	ans /= 2
if 2 ** z <= n:
	print(int(2 ** z + ans))
else:
	print(int(ans))


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	import math
	x = int(math.log(n, 2))
	if 2 ** x > n:
		x -= 1
	print(2 ** (x + 1) - 1)


x = input().split()
n = int(x[0])
k = int(x[1])
if n == 1:
	print(1)
elif k == 1:
	print(n)
else:
	power = len(f'{n:b}')
	print(2 ** power - 1)


(n, k) = [int(v) for v in input().split()]
if k == 1:
	print(n)
else:
	nn = n
	p = 0
	while nn:
		nn //= 2
		p += 1
	print(2 ** p - 1)


def read():
	return list(map(int, input().split()))
(n, k) = read()
if k == 1:
	print(n)
else:
	ans = 0
	for i in range(len(bin(n)[2:])):
		ans += 2 ** i
	print(ans)


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(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
MAXN = int(10000000.0 + 5)

def spf_sieve():
	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, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, k) = int_array()
if k == 1:
	print(n)
else:
	s = bin(n).replace('0b', '')
	t = '1' * len(s)
	t = int(t, 2)
	x = n ^ t
	print(n + x)


(n, k) = map(int, input().split())
ans = bin(n).replace('0b', '')
ans = list(ans)
if k == 1:
	ans = n
else:
	ans = 2 ** len(ans) - 1
print(ans)


(n, k) = (int(x) for x in input().split())
if k == 1:
	ans = n
else:
	kk = 0
	nn = n
	while nn != 0:
		kk += 1
		nn //= 2
	ans = 2 ** kk - 1
print(ans)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit()
for i in range(61):
	num = 2 ** i
	if num >= n:
		print(num * (2 if num == n else 1) - 1)
		break


def my_power(n):
	ans = 1
	for i in range(0, n):
		ans = ans * 2
	return ans
data = list(map(int, input().split(' ')))
if data[1] == 1:
	print(data[0])
else:
	s = bin(data[0])
	print(my_power(len(s) - 2) - 1)


x = input()
a = x.split(' ')
p = int(a[0])
q = int(a[1])
if q == 1:
	print(p)
else:
	bt = 1
	while bt < p:
		bt = 2 * bt + 1
	print(bt)


from math import log2 as log
from math import floor as fl
(n, k) = [int(p) for p in input().split()]
maxBits = len(bin(n)) - 2
if k == 1:
	print(n)
	exit()
a1 = 2 ** (maxBits - 1)
a2 = a1 - 1
print(a1 ^ a2)


def main():
	(n, k) = map(int, input().split())
	print(n if k == 1 else (1 << n.bit_length()) - 1)
main()


import sys
(n, m) = map(int, input().split())
r = 1
while r * 2 <= n:
	r *= 2
print(r * 2 - 1 if m > 1 else n)


(n, k) = [int(a) for a in input().strip().split()]
ans = 0
if k == 1:
	ans = n
else:
	base = 1
	while n // 2:
		base *= 2
		n = n // 2
	ans = 2 * base - 1
print(str(ans))


import math
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, k) = M()
d = len(bin(n)[2:])
if k == 1:
	print(n)
else:
	print(2 ** d - 1)


read = lambda : map(int, input().split())
(n, k) = read()
if k == 1:
	print(n)
else:
	bit = 0
	while n:
		n //= 2
		bit += 1
	print(pow(2, bit) - 1)


def list_output(s):
	print(' '.join(map(str, s)))

def list_input(s='int'):
	if s == 'int':
		return list(map(int, input().split()))
	elif s == 'float':
		return list(map(float, input().split()))
	return list(map(str, input().split()))
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	l = 0
	x = n
	while x > 0:
		x //= 2
		l += 1
	print(2 ** l - 1)


import math

def hbit(n):
	ans = 0
	while n != 0:
		ans += 1
		n = n >> 1
	return ans
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	val = hbit(n)
	print(2 ** val - 1)


def convert(i):
	if i == 0:
		return '0'
	s = ''
	while i > 0:
		if i % 2 == 1:
			s = '1' + s
		else:
			s = '0' + s
		i = i // 2
	return s
t = input()
t = t.split()
a1 = int(t[0])
a2 = int(t[1])
nn = convert(a1)
nn2 = []
for k in range(0, len(nn)):
	nn2.append(nn[k])
for i in range(0, len(nn2)):
	if nn2[i] == '0':
		nn2[i] = '1'
nn = ''
for i in nn2:
	nn = nn + str(i)
if a2 == 1:
	print(a1)
else:
	print(int(nn, 2))


(n, k) = [int(x) for x in input().strip().split()]
if k == 1:
	print(n)
else:
	r = 1
	while r <= n:
		r *= 2
	print(r - 1)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 15
mod = 10 ** 9 + 7

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(a, b) = LI()
	if b == 1:
		return a
	i = 1
	while 2 ** i <= a:
		i += 1
	return 2 ** i - 1
print(main())


import math
(n, k) = list(map(int, input().split()))
print(n if k == 1 else 2 ** math.floor(int.bit_length(n)) - 1)


(x, y) = [int(x) for x in input().split()]
if y == 1:
	print(x)
else:
	nb = x.bit_length()
	print(2 ** nb - 1)


import sys
while True:
	try:
		(n, k) = map(int, input().strip().split())
		if k == 1:
			print(n)
		else:
			ans = 1
			while ans < n:
				ans = ans * 2 + 1
			print(ans)
	except EOFError:
		break


(n, k) = [int(i) for i in input().strip().split()]
bi = list(bin(n)[2:])
l = len(bi)
if k == 1:
	print(n)
else:
	print(2 ** l - 1)


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().rstrip().split())
if k == 1:
	print(n)
else:
	x = 1
	while 2 * x <= n:
		x *= 2
	print(2 * x - 1)


(x, y) = map(int, input().split())
if y == 1:
	print(x)
else:
	res = 0
	while x > 0:
		res += 1
		x //= 2
	print((1 << res) - 1)


def countlog(n):
	tmpn = int(n)
	count = int(0)
	while tmpn > 0:
		tmpn = int(tmpn / 2)
		count = count + 1
	return count - 1
entrada = input().split()
n = int(entrada[0])
k = int(entrada[1])
tmpn = n
count = countlog(tmpn) + 1
tempy = tempx = pow(2, count) - 1
result = -1
if k == 1:
	result = n
else:
	while k > 0:
		tempx = tempx ^ tmpn
		if tempx < n:
			result = tempy
			break
		else:
			result = n
			break
		k = k - 1
print(result)


from math import log2
(a, b) = [int(x) for x in input().split()]
print(a if b == 1 else 2 ** len('{0:b}'.format(a)) - 1)


def main():
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
		return
	p = 1
	while p << 1 <= n:
		p <<= 1
	print((p << 1) - 1)
main()


import sys
(n, k) = map(int, sys.stdin.readline().strip().split())
if k == 1:
	print(n)
else:
	import math
	st = bin(n)[2:]
	cnt = 0
	pp = 0
	for s in st:
		if s == '1':
			cnt += 1
		pp += 1
	if pp == cnt:
		print(n)
	else:
		p = int(math.floor(math.log(n, 2))) + 1
		print(2 ** p - 1)


from sys import stdin
(n, k) = map(int, stdin.readline().split(' '))
answer = 0
if k == 1:
	answer = n
else:
	aux = bin(n)[2:]
	aux = '1' * len(aux)
	answer = int(aux, 2)
print(answer)


import collections
import math
import timeit
import sys

def power_bit_length(x):
	return 2 ** (x - 1).bit_length()

def shift_bit_length(x):
	return 1 << (x - 1).bit_length()

def power_log(x):
	return 2 ** math.ceil(math.log(x, 2))
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	ans = 1
	while ans <= n:
		ans *= 2
	print(ans - 1)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre
maxint = 10 ** 24

def kadane(a, size):
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
dp = [0] * 64
dp[0] = 1
for i in range(1, 64):
	dp[i] = dp[i - 1] * 2
for _ in range(1):
	(a, b) = cin()
	if b == 1:
		print(a)
	else:
		p = bi.bisect(dp, a)
		print(dp[p] - 1)


import math
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	l = 0
	while n > 0:
		n = n // 2
		l += 1
	ans = 1
	for i in range(l):
		ans = ans * 2
	print(ans - 1)


def new_year(n, k):
	if k == 1:
		return n
	result = 1
	while result < n:
		result = 2 * result + 1
	return result
(N, K) = [int(i) for i in input().split()]
print(new_year(N, K))


(N, K) = map(int, input().split())
if K == 1:
	print(N)
else:
	cnt = 0
	while N > 0:
		N >>= 1
		cnt += 1
	print((1 << cnt) - 1)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	max_sum = ''
	for i in range(n.bit_length()):
		max_sum += '1'
	print(int(max_sum, 2))


getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
(x, y) = getInputIntList()
s = bin(x)
s = s[2:len(s)]
if y != 1:
	l = '1' * len(s)
	print(int(l, 2))
else:
	print(x)


(n, k) = map(int, input().strip().split())
largest_power = bin(n)[2:]
cur = int(largest_power, 2)
best = str((2 << len(largest_power) - 1) - 1)
print(cur if k == 1 else best)


(n, m) = map(int, input().split())
if n < 2:
	print(n)
elif m != 1:
	s = bin(n)
	s = s[2:]
	s = s.replace('0', '1')
	print(int(s, 2))
elif m == 1:
	print(n)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	a = int.bit_length(n)
	print((1 << a) - 1)


def binary(n):
	s = ''
	while n > 0:
		rem = n % 2
		n = n // 2
		s += str(rem)
	return len(s)

def decimal(n):
	ans = 0
	for i in range(n):
		ans += 2 ** i
	return ans
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	x = binary(n)
	ans = decimal(x)
	print(ans)


(a, d) = map(int, input().split())
b = 0
c = 0
while 2 ** (b + 1) <= a:
	b += 1
if d > 1:
	print(2 ** (b + 1) - 1)
	quit()
print(a)


import sys
(n, k) = map(int, input().split())
if k == 1:
	print(n)
	sys.exit(0)
msb = n.bit_length()
answer = 0
for i in range(msb):
	answer <<= 1
	answer += 1
print(answer)


import math
(n, k) = map(int, input().split())
if k > 1:
	s = '{0:b}'.format(n)
	p = len(s)
	print(pow(2, p) - 1)
else:
	print(n)


I = input().split()
n = int(I[0])
k = int(I[1])
if k == 1:
	print(n)
else:
	t = 1
	while t <= n:
		t *= 2
	print(t - 1)


import math

class CodeforcesTask912BSolution:

	def __init__(self):
		self.result = ''
		self.n_k = []

	def read_input(self):
		self.n_k = [int(x) for x in input().split(' ')]

	def process_task(self):
		if self.n_k[1] > 1:
			z = math.log2(self.n_k[0])
			if 2 ** z > self.n_k[0]:
				z = math.ceil(z)
				self.result = str(2 ** z - 1)
			else:
				if z.is_integer():
					z += 1
				z = math.ceil(z)
				self.result = str(2 ** z - 1)
		else:
			self.result = str(self.n_k[0])

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


(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit(0)
k -= 1
length = n.bit_length()
print(2 ** length - 1)


(n, k) = map(int, input().split())

def a(x):
	if x == 0:
		return '0'
	res = ''
	while x > 0:
		res = ('0' if x % 2 == 0 else '1') + res
		x //= 2
	return res
step = 0
sm = 0
if k == 1:
	print(n)
else:
	for i in range(len(str(a(n)))):
		now = 2 ** step
		sm += now
		step += 1
	print(sm)


(n, k) = map(int, input().split())
num = len(bin(n)[2:])
if k == 1:
	print(n)
else:
	ans = pow(2, num) - 1
	print(ans)


(n, k) = map(int, input().split(' '))
if k == 1:
	print(n)
else:
	for i in range(64):
		if n >> i & 1:
			k = 1 << i
	print((k << 1) - 1)


(n, k) = [int(x) for x in input().split()]
if k == 1:
	print(n)
else:
	a = bin(n)[2:]
	print((1 << len(a)) - 1)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	ans = 1
	ans = 1
	for i in range(0, 100):
		ans = ans * 2
		if ans > n:
			break
	print(ans - 1)


import math
import sys
import bisect
from heapq import heapify, heappop, heappush
from itertools import *
from collections import deque, OrderedDict
from pprint import pprint
sys.setrecursionlimit(10 ** 6)
II = lambda : sys.stdin.readline()
inp = lambda : int(II())
inpm = lambda : map(int, II().split())
inpl = lambda : list(inpm())
DEBUG = False

def set_debug(deb: bool=True):
	global DEBUG
	DEBUG = deb

def debug(**kwargs):
	if DEBUG:
		arr = []
		for (k, w) in kwargs.items():
			arr.append(f'{k}: {w}')
		print(*arr, sep=', ')
(WHITE, GREY, BLACK, RED) = (0, 1, 2, 3)
EPS = 1e-09
INF = int(1e+18)
MOD = int(1000000000.0) + 7
N = 2000009

def solve():
	(n, k) = inpm()
	if k == 1:
		print(n)
	else:
		i = 0
		while n >> 1 > 0:
			n >>= 1
			i += 1
		print((1 << i + 1) - 1)

def main():
	t = 1
	for i in range(t):
		solve()
main()


(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit()
print((1 << n.bit_length()) - 1)


inp = input().split()
n = int(inp[0])
k = int(inp[1])
pow2 = 1
while pow2 <= n:
	pow2 *= 2
if k == 1:
	print(int(n))
else:
	print(int(pow2 - 1))


import sys
import math
(n, k) = map(int, input().split())
finale = 1
if k == 1:
	print(n)
	sys.exit(0)
else:
	while finale < n:
		finale = finale * 2 + 1
	print(finale)


(n, k) = map(int, input().split())
x = n
summ = 0
while n != 0:
	n = n // 2
	summ += 1
if k > 1:
	print(2 ** summ - 1)
else:
	print(x)


import sys
(n, k) = [int(s) for s in input().split()]
if k == 1:
	print(n)
else:
	copy = n
	array = []
	while n != 0:
		array.append(n % 2)
		n = n // 2
	array = array[::-1]
	num = 0
	sum_ = 0
	for i in range(len(array)):
		if not array[i]:
			num += 2 ** (len(array) - i - 1)
		sum_ += 2 ** i
	if num < copy:
		print(sum_)
	else:
		print(copy)


def main():
	(n, k) = map(int, input().split())
	print((1 << n.bit_length()) - 1 if n & n + 1 and k > 1 else n)
try:
	while True:
		main()
except EOFError:
	pass


(n, d) = map(int, input().split())
x = 0
if d == 1:
	exit(print(n))
while n > 0:
	x += 1
	n >>= 1
exit(print((1 << x) - 1))


(n, k) = map(int, input().split())
if k > 1:
	s = '1' * len('{0:b}'.format(n))
	print(int(s, 2))
else:
	print(n)


def count(n):
	c = 0
	while n > 0:
		c += 1
		n >>= 1
	return c
(n, k) = map(int, input().split())
c = count(n)
if k == 1:
	print(n)
else:
	print((1 << c) - 1)


(n, m) = map(int, input().split())
if m == 1:
	print(n)
else:
	i = 0
	l = 0
	while l < n:
		l += 2 ** i
		i += 1
	print(l)


(n, k) = map(int, input().split())
bit = 0
temp = n
while n:
	bit += 1
	n = n // 2
m = 1
if k == 1:
	print(temp)
	exit(0)
ans = 0
for i in range(bit):
	ans += m * 1
	m *= 2
print(ans)


import math
(n, k) = map(int, input().split())
if k > 1:
	a = [2 ** i for i in range(64)]
	for i in range(64):
		if a[i] == n:
			print(a[i + 1] - 1)
			exit()
		elif a[i] > n:
			print(a[i] - 1)
			exit()
else:
	print(n)


from math import log, floor
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	count_bits = 0
	while n != 0:
		n >>= 1
		count_bits += 1
	print(2 ** count_bits - 1)


def getNum(a):
	res = 0
	for i in range(0, len(a)):
		if a[i] == '0':
			res += 1 << len(a) - 1 - i
	return res
(n, k) = map(int, input().split())
res = n
for i in range(k - 1):
	buff = list(bin(res)[2:])
	f = True
	for i in buff:
		if i == '0':
			f = False
	if f == True:
		break
	res = res ^ getNum(buff)
print(res)


R = lambda : map(int, input().split())
(n, k) = R()
if k == 1:
	print(n)
else:
	print(pow(2, len(bin(n)) - 2) - 1)


from math import log
(n, k) = [int(i) for i in input().split()]
b = 0
while 1 << b <= n:
	b += 1
if k == 1:
	print(n)
else:
	print((1 << b) - 1)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())

def exit():
	return sys.exit(0)
MAX = float('inf')
MIN = float('-inf')

def main():
	(n, k) = ain()
	if k == 1:
		print(n)
		exit()
	else:
		l = list(bin(n))
		l = l[::-1]
		ans = 0
		x = 1
		for i in l:
			if i == 'b':
				break
			ans += x
			x = x * 2
		print(ans)
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()


def maxXorSum(n, k):
	if k == 1:
		return n
	ans = 1
	while ans <= n:
		ans <<= 1
	return ans - 1
(n, k) = map(int, input().split())
print(maxXorSum(n, k))


from math import *
(n, k) = map(int, input().split())
nbrb = len(bin(n)) - 2
mx = 2 ** nbrb - 1
if k == 1:
	print(n)
else:
	print(mx)


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')

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()]
(n, k) = value()
if k == 1:
	print(n)
	exit()
k = int(log2(n))
if k == int(k) and n == 2 ** k - 1:
	print(2 ** k - 1)
else:
	print(2 ** (k + 1) - 1)


(n, k) = map(int, input().split())

def setBitNumber(n):
	i = 0
	while n > 0:
		i += 1
		n = n >> 1
	return i
itr = setBitNumber(n)
ans = (1 << itr) - 1
if k > 1:
	print(ans)
else:
	print(n)


import math
from decimal import Decimal

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)
(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit()
ans = 1
while ans < n:
	ans = ans * 2 + 1
print(ans)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	res = 1
	while res <= n:
		res <<= 1
	print(res - 1)


(n, k) = [int(f) for f in input().split(' ') if f]
if k == 1:
	print(n)
else:
	l = 0
	while n > 0:
		l += 1
		n //= 2
	print(2 ** l - 1)


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
(n, k) = map(int, input().split())
ans = 0
if k == 1:
	ans = n
else:
	ans = int('1' * len(bin(n)[2:]), 2)
print(ans)


import math
(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	ax = bin(n)
	ax = ax[2:]
	xs = len(ax)
	ys = 2 ** xs - 1
	print(ys)


(n, k) = [int(i) for i in input().strip().split()]
if k == 1:
	print(n)
else:
	print(int(bin(n)[2:].replace('0', '1'), 2))


(n, k) = list(map(int, input().split()))
n_bin = bin(n)[2:]
bin_len = len(n_bin)
if k > 1:
	print(2 ** bin_len - 1)
else:
	print(n)


def checkMaxXor():
	(n, k) = map(int, input().split())
	if k == 1:
		print(n)
		return
	if n == 1:
		print(1)
		return
	pagli = n
	(i, j) = (1, 2)
	while n > 0:
		t = i
		i = i + j
		j = i + 1
		n = pagli - i
		if n >= j:
			n -= j
	if j <= pagli:
		print(i ^ j)
	else:
		print(i)
checkMaxXor()


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, k) = f()
s = list(bin(n))
if k > 1:
	for i in range(3, len(s)):
		s[i] = '1'
	print(int(''.join(s), 2))
else:
	print(n)


(n, k) = map(int, input().split(' '))
if k == 1:
	print(n)
else:
	s = len(bin(n)[2:])
	count = 0
	print(2 ** s - 1)


(x, y) = map(int, input().split())
a = len(bin(x)) - 2
if y != 1:
	print(2 ** a - 1)
else:
	print(x)


(n, k) = map(int, input().split())
if k == 1:
	print(n)
	exit()
for i in range(61, -1, -1):
	if n >> i & 1 == 1:
		print((1 << i + 1) - 1)
		exit()


(n, k) = map(int, input().split())
if k == 1:
	print(n)
else:
	b = len(bin(n)) - 2
	X = 0
	for i in range(b):
		X += pow(2, b - (i + 1))
	print(X)


(n, k) = [int(x) for x in input().split()]
power = 1
while power <= n:
	power *= 2
if k == 1:
	print(n)
else:
	print(power - 1)


(n, k) = map(int, input().split())
best_set = [n]
answer = n
biggest_zero_bit = 0
bit_rep = bin(answer)[2:]
bit_rep_anti = ''
if k > 1:
	for i in range(len(bit_rep)):
		if bit_rep[i] == '0':
			bit_rep_anti += '1'
		else:
			bit_rep_anti += '0'
	decimal_anti = int(bit_rep_anti, 2)
	answer = answer ^ decimal_anti
print(answer)


import math

def calc(a):
	i = 0
	while 1 << i <= a:
		i += 1
	return i
(A, B) = input().split()
a = int(A)
b = int(B)
if b == 1:
	print(a)
else:
	print((1 << calc(a)) - 1)