At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$

We can see that if we choose some value $v$ and will apply function $f$ to it, then apply $f$ to $f(v)$, and so on, we'll eventually get $1$. Let's write down all values we get in this process in a list and denote this list as $path(v)$. For example, $path(1) = [1]$, $path(15) = [15, 14, 7, 6, 3, 2, 1]$, $path(32) = [32, 16, 8, 4, 2, 1]$.

Let's write all lists $path(x)$ for every $x$ from $1$ to $n$. The question is next: what is the maximum value $y$ such that $y$ is contained in at least $k$ different lists $path(x)$?

Formally speaking, you need to find maximum $y$ such that $\left| \{ x ~|~ 1 \le x \le n, y \in path(x) \} \right| \ge k$.


-----Input-----

The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 10^{18}$).


-----Output-----

Print the only integer — the maximum value that is contained in at least $k$ paths.


-----Examples-----
Input
11 3

Output
5

Input
11 6

Output
4

Input
20 20

Output
1

Input
14 5

Output
6

Input
1000000 100

Output
31248



-----Note-----

In the first example, the answer is $5$, since $5$ occurs in $path(5)$, $path(10)$ and $path(11)$.

In the second example, the answer is $4$, since $4$ occurs in $path(4)$, $path(5)$, $path(8)$, $path(9)$, $path(10)$ and $path(11)$.

In the third example $n = k$, so the answer is $1$, since $1$ is the only number occuring in all paths for integers from $1$ to $20$.

Difficulty: interview

Starter code:

Solutions:
def gg(n,lol):
	ans = 0
	cur = 1
	lol2 = lol
	while(2*lol+1<=n):
		cur *= 2
		ans += cur
		lol = 2*lol+1
		lol2 *= 2
	if lol2*2 <= n:
		ans += n-lol2*2+1	
	return ans

n,k = list(map(int,input().split()))
low = 1
high = n//2
res = 1
while low <= high:
	mid = (low+high)//2
	if gg(n,mid) >= k:
		res = mid
		low = mid+1
	else:
		high = mid-1
if n == k:
	print(1)
elif(gg(n,res)-1-gg(n,res*2) >= k):
	print(res*2+1)
else:
	print(res*2)					


def ans(m, n):
    q1, q2, k = m, 2, 0
    while q1 <= n:
        q1 *= 2
        k += q2
        q2 *= 2
    q2 //= 2
    q1 //= 2
    if n-q1 < q2:
        return k+n-q1-q2+1
    return k


n, k = list(map(int, input().split()))
if k == n:
    print(1)
elif k == 1:
    print(n)
else:
    l, r = 1, n//2+1
    while r-l > 1:
        m = (l+r)//2
        if ans(2*m, n) >= k:
            l = m
        else:
            r = m
    l1, r1 = 1, n // 2 + 1
    while r1 - l1 > 1:
        m = (l1 + r1) // 2
        if ans(2 * m, n) >= k-1:
            l1 = m
        else:
            r1 = m
    print(max(l1, 2*l))


n, k = list(map(int, input().split()))
s = bin(n)[2:]

ans = 1
if k == 1:
    ans = n
else:
    f = len(s)
    for d in range(1, f):
        rgt = int(s[-d:], 2)
        lft = int(s[:-d], 2)
        c = 2**d
        # print(d, lft, rgt+c, 2*c-1)
        if rgt+c >= k:
            if rgt+c > k:
                ans = max(lft*2, ans)
            else:
                ans = max(lft, ans)
        if 2*c-1 >= k:
            if 2*c-1 > k:
                ans = max((lft-1)*2, ans)
            else:
                ans = max(lft-1, ans)

print(ans)


import sys

def cnt(y, n):
    # print("in count")
    #print(y)
    if y <= 1:
        return n
    if y > n:
        return 0
    if y % 2 == 1:
        return 1 + cnt(2 * y, n)
    c = 0
    p = 1
    while p*y <= n:
        mx = min(n, p*y + 2*p - 1)
        c += mx - p*y + 1
        p *= 2
    return c

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

if k == 1:
    print(n)
    return

l, h = 1, n // 2
while l < h:
    m = (l + h) // 2
    #print("l = " + str(l))
    #print("h = " + str(h))
    #print("m = " + str(m))
    #print("cnt = " + str(cnt(m, n)))

    if cnt(2 * m, n) < k:
        h = m
    else:
        l = m + 1
mx_even = 2 * l - 2
    
l, h = 1, n // 2
while l < h:
    m = (l + h) // 2
    #print("l = " + str(l))
    #print("h = " + str(h))
    #print("m = " + str(m))
    #print("cnt = " + str(cnt(m, n)))

    if cnt(2 * m + 1, n) < k:
        h = m
    else:
        l = m + 1
mx_odd = 2 * l - 1
#assert(cnt(mx_odd, n) >= k)
#assert(cnt(mx_even, n) >= k)

mx_heur = -1
i = 0
while i < 20 and n - i > 0:
    if cnt(n - i, n) >= k:
        mx_heur = n - i
        break
    i += 1

print(max(mx_even, max(mx_odd, mx_heur)))


n,k=map(int,input().split())
def c(m):
  a=b=m
  ans=0
  if m%2==0:b+=1
  while b<=n:
    ans+=b-a+1
    a*=2
    b*=2
    b+=1
  return ans+max(0,n-a+1)

if n<100:
  ans=1
  for i in range(1,n+1):
    if c(i)>=k:ans=i
  print(ans);return
for i in range(n,n-100,-1):
  if c(i)>=k:print(i);return

ng=0
ok=(n+1)//2*2
while ng+2!=ok:
  mid=(ok+ng)//4*2
  if c(mid)<k:ok=mid
  else:ng=mid
x=ng
ng=-1
ok=(n+1)//2*2-1
while ng+2!=ok:
  mid=(ok+ng)//4*2+1
  if c(mid)<k:ok=mid
  else:ng=mid
print(max(ng,x))

a, b = input().split()
a = int(a)
b = int(b)

if b == 1:
	print(a)
elif b == 2:
	if a % 2 == 0:
		print(a // 2)
	else:
		print(a-1)
else:

	chopped_even = bin(b+1)[3:]
	len_even = len(chopped_even)
	best_even = ((a - int(chopped_even, 2))//(2**len_even))*2

	chopped_odd = bin(b)[2:]
	len_odd = len(chopped_odd)
	best_odd = ((a - b) // (2**len_odd))*2 + 1

	if best_even > best_odd:
		print(best_even)
	else:
		print(best_odd)

def gg(n, lol):
    ans = 0
    cur = 1
    lol2 = lol
    while (2 * lol + 1 <= n):
        cur *= 2
        ans += cur
        lol = 2 * lol + 1
        lol2 *= 2
    if lol2 * 2 <= n:
        ans += n - lol2 * 2 + 1
    return ans


n, k = map(int, input().split())
low = 1
high = n // 2
res = 1
while low <= high:
    mid = (low + high) // 2
    if gg(n, mid) >= k:
        res = mid
        low = mid + 1
    else:
        high = mid - 1
if n == k:
    print(1)
elif (gg(n, res) - 1 - gg(n, res * 2) >= k):
    print(res * 2 + 1)
else:
    print(res * 2)

import sys

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

def mint():
	return int(minp())

def mints():
	return list(map(int,minp().split()))

def full(x, n):
	if ((n + 1) & n) != 0:
		raise Exception("qwe")
	r = 1
	while True:
		if r >= x:
			return n
		if n == 1:
			return None
		r *= 2
		n -= 1
		if r >= x:
			return n
		n //= 2
		r += 1

def is_good(x, n):
	l = x
	r = x
	rp = x
	if x % 2 == 0:
		return None
	while l <= n:
		if l <= n and r > n:
			return None
		l *= 2
		rp = r
		r = r * 2 + 1
	return rp

def full2(x, c, rp):
	r = 1
	while True:
		if r >= x:
			return rp
		if rp == c:
			return None
		r *= 2
		rp -= 1
		if r >= x:
			return rp
		rp //= 2
		r += 1
	return None


def full1(k, x, n):
	rp = is_good(x, n)
	if rp == None:
		r = None
		if f(x, n) >= k:
			r = x
		if 2*x <= n:
			r1 = full1(k, 2*x, n)
			if r1 != None and (r == None or r < r1):
				r = r1
		if 2*x + 1 <= n:
			r1 = full1(k, 2*x + 1, n)
			if r1 != None and (r == None or r < r1):
				r = r1
		return r
	else:
		return full2(k, x, rp)

def fulls(k, n):
	r = 1
	for i in range(1,n+1):
		if f(i,n) >= k:
			r = i
	return r

def f(x, n):
	r = 0
	rp = is_good(x, n)
	if rp != None:
		r = 1
		while rp != x:
			r = (r*2 + 1)
			rp //= 2
		return r

	if x <= n:
		r += 1
	if x % 2 == 0 and x + 1 <= n:
		r += f(x + 1, n)
	if 2 * x <= n:
		r += f(x * 2, n)
	#print(x, r)
	return r

def f1(x, n):
	r = 0
	if x <= n:
		r += 1
	if x % 2 == 0 and x + 1 <= n:
		r += f(x + 1, n)
	if 2 * x <= n:
		r += f(x * 2, n)
	#print(x, r)
	return r

'''
from random import randint
while True:
	n = randint(1, 1024)
	x = randint(1, n)
	if full1(x, 1, n) != fulls(x, n):
		print(x, n, full1(x, 1, n), fulls(x,n))
'''
n, k = mints()
print(full1(k, 1, n))


from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)

def check(ch):
	if(ch > n): return 0
	if(ch %2 == 0):
		if(ch == n): return 1
		else: 
			st = 4
			ans = 2
	else:
		st = 2
		ans  = 1
	ch *= 2
	while(ch < n):
		if(ch > n + 1 - st):
			ans += n+1-ch
			break
		else:
			ans += st
		st *= 2
		if(ch > n - ch):
			break
		else:
			ch *= 2
	return ans


mod = 10**9 + 7
n,x = map(int,input().split())

l = 1
r = n
ans1 = 0
while(r >= l):
	mid = (r+l)//2
	mid *= 2
	if(check(mid) >= x):
		l = mid//2 + 1
		ans1 = mid
	else:
		r = mid//2 - 1
	#print(mid,check(mid))
l = 1
r = n
ans2 = 0
while(r >= l):
	mid = (r+l)//2
	mid = mid*2-1
	if(check(mid) >= x):
		l = (mid+1)//2 + 1
		ans2 = mid
	else:
		r = (mid+1)//2 - 1
	#print(mid,check(mid))
print(max(ans1,ans2))