Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height h. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. 

Let's index all the leaf nodes from the left to the right from 1 to 2^{h}. The exit is located at some node n where 1 ≤ n ≤ 2^{h}, the player doesn't know where the exit is so he has to guess his way out!

Amr follows simple algorithm to choose the path. Let's consider infinite command string "LRLRLRLRL..." (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules:  Character 'L' means "go to the left child of the current node";  Character 'R' means "go to the right child of the current node";  If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node;  If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command;  If he reached a leaf node that is not the exit, he returns to the parent of the current node;  If he reaches an exit, the game is finished. 

Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit?


-----Input-----

Input consists of two integers h, n (1 ≤ h ≤ 50, 1 ≤ n ≤ 2^{h}).


-----Output-----

Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm.


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

Output
2
Input
2 3

Output
5
Input
3 6

Output
10
Input
10 1024

Output
2046


-----Note-----

A perfect binary tree of height h is a binary tree consisting of h + 1 levels. Level 0 consists of a single node called root, level h consists of 2^{h} nodes called leaves. Each node that is not a leaf has exactly two children, left and right one. 

Following picture illustrates the sample test number 3. Nodes are labeled according to the order of visit.

[Image]

Difficulty: interview

Starter code:

Solutions:
h, n = list(map(int, input().split()))
c, m = 0, 2 ** h
r = 0
while m > 1:
    if c == 0:
        if n > m // 2:
            r += m - 1
            n -= m // 2
            c = 1 - c
    else:
        if n > m // 2:
            n -= m // 2
        else:
            r += m - 1
            c = 1 - c
    c = 1 - c
    r += 1
    m //= 2
    #print(c, m, r, n)
print(r)


"""
Codeforces Contest 287 Div 2 Problem C

Author  : chaotic_iak
Language: Python 3.4.2
"""

################################################### SOLUTION

def main():
    h,n = read()
    n -= 1
    n = bin(n)[2:]
    n = "0" * (h-len(n)) + n

    s = ""
    for i in range(h):
        if i and n[i-1] == "0":
            s += "1" if n[i] == "0" else "0"
        else:
            s += n[i]

    ct = 0
    for i in range(h):
        ct += 1
        if s[i] == "1": ct += 2**(h-i)-1
    print(ct)

#################################################### HELPERS



def read(mode=2):
    # 0: String
    # 1: List of strings
    # 2: List of integers
    inputs = input().strip()
    if mode == 0: return inputs
    if mode == 1: return inputs.split()
    if mode == 2: return list(map(int, inputs.split()))

def write(s="\n"):
    if s is None: s = ""
    if isinstance(s, list): s = " ".join(map(str, s))
    s = str(s)
    print(s, end="")

write(main())

height, n = list(map(int, input().split()))

s = height
reverted = False
for h in range(height-1, -1, -1):

    if n > 2**h:
        more = True
        n -= 2**h
    else:
        more = False

    if more ^ reverted:
        s += (2 * 2**h - 1)

    reverted = not more

print (s)


h,n=list(map(int,input().split()))
p=1<<(h-1)
i=r=0
n-=1
while h:
	r+=1
	if n>=p:j=1;n-=p
	else:j=0
	if j^i:r+=p+p-1
	else:i=1-i
	p>>=1
	h-=1
print(r)


def summ(x):
    ret=1
    acc=1
    while(acc<=x):
        ret+=acc
        acc*=2
    return ret

h,n=list(map(int,input().split()))

ans = 1
lvl = 0
cur = 'L'
amnt = 2**h
while(1):
    if(lvl==h):
        break
    if(cur=='L'):
        if(n<=amnt//2):
            amnt//=2
            cur='R'
            ans+=1
            lvl+=1
        else:
            amnt//=2
            n-=amnt
            cur='L'
            ans+=summ(amnt)
            lvl+=1
    else:
        if(n<=amnt//2):
            amnt//=2
            cur='R'
            ans+=summ(amnt)
            lvl+=1
        else:
            amnt//=2
            n-=amnt
            cur='L'
            ans+=1
            lvl+=1
print(ans-1)


H, N = [int(i) for i in input().split()]

result = 0
side = 0
for h in range(H, 0, -1):
    result += 1
    if side ^ (N > 1 << (h - 1)):
        result += (1 << h) - 1
    else:
        side ^= 1
    if N > 1 << (h - 1):
        N -= 1 << (h - 1)
    
print(result)


h,n = map(int, input().split(' '))
ans = 0
left = True
for i in range(h) :
    ch = h-i
    half = 2**(ch-1)
    
    if n <= half :
        if left :
            ans += 1
            left = False
            continue
        else :
            ans += half*2
            left = False
            continue
    else :
        if left :
            ans += half*2
            left = True
            n -= half
        else :
            ans += 1
            left = True
            n -= half
print(ans)

line = input().split()

h = int(line[0])
n = int(line[1])

last = 1
th = 2 ** h
ans = 1
l = 1
r = th
while th > 0:
    mid = (l + r) // 2
    if n <= mid:
        if last == 1:
            ans += 1
        else:
            ans += th
        last = 0
        r = mid
    else:
        if last == 0:
            ans += 1
        else:
            ans += th
        last = 1
        l = mid + 1
    th = th // 2

print(str(ans - 2))


def ans():
    h, n= [int(i) for i in input().split()]
    div= 2**(h- 1)
    mystr= ""
    for i in range(h):
        #print(div)
        if n> div:
            mystr+= "G"
            div+= 2**(h- i- 2)
        else:
            mystr+= "L"
            div-= 2**(h- i- 2)
    
    #print(mystr)
    if mystr[0]== "L":
        ans= 1
    elif mystr[0]== "G":
        ans= 2**h
    for i in range(len(mystr)- 1):
        if mystr[i+ 1]== mystr[i]:
            ans+= 2**(h- i- 1)
        else:
            ans+= 1
    
    print(ans)
        
    
    
    return
ans()

h,n = list(map(int,input().split()))
l = 1; r = 2**h
ans = 0
now = 'l'
for i in range(h,0,-1):
    if n < (l+r)/2 and now == 'l':
        now = 'r'
        r -= 2**(i-1)
        ans += 1
    elif n < (l+r)/2 and now == 'r':
        r -= 2**(i-1)
        ans += 2**i
    elif n > (l+r)/2 and now == 'l':
        l += 2**(i-1)
        ans += 2**i
    else:
        now = 'l'
        l += 2**(i-1)
        ans += 1
print(ans)


__author__ = 'Konrad Strack'


def command_gen():
    while True:
        yield 'L'
        yield 'R'


def solve():
    h, n = [int(x) for x in input().split()]

    leaves = 2 ** h

    path = []
    left, right = 1, leaves
    for i in range(h):
        middle = (left + right) // 2
        if n <= middle:
            path.append('L')
            right = middle
        else:
            path.append('R')
            left = middle + 1

    command = command_gen()
    sum = 0
    hi = h
    for p in path:
        cmd = next(command)

        if p != cmd:
            sum += 2 ** hi - 1
            next(command)
        hi -= 1

    sum += len(path)
    print(sum)


def __starting_point():
    solve()
__starting_point()

h, n = map(int, input().split())
t = bin(n-1)[2:]
t = '0'*(h-len(t))+t
res = 0
flag = True
for i in range(h):
	if(t[i] == ('1' if flag else '0')):
		res += 2**(h-i)
	else:
		flag = not flag
		res += 1
print(res)

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

total = 2 ** (h + 1) - 1

sum_v = 0
range_v = (0, 2 ** h - 1)
prev_r = range_v
x = n - 1
left = False
curr_h = 0


def in_range(r, x):
    return r[0] <= x <= r[1]


def range_width(r):
    return r[1] - r[0] + 1


def update_range(r, l):
    w = range_width(r) // 2
    st = r[0] if l else r[0] + w
    return st, st + w - 1

#print("X ", x)
while range_width(range_v) != 0:
    left = not left
    #print(range_v)

    tmp = range_v
    if in_range(range_v, x):
        range_v = update_range(range_v, left)
        sum_v += 1
        curr_h += 1
        #print("+ 1")
    else:
        range_v = update_range(prev_r, left)
        sum_v += 2 ** (h - curr_h + 1) - 1
        #print("+ ", 2 ** (h - curr_h + 1) - 1)

    prev_r = tmp

print(sum_v - 1)

import math
s = 'LRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLR'
(h, n) = [int(x) for x in input().split()]
n = 2**(h)-1+n
left = 2**h
right = 2**(h+1)-1
path = []
for i in range(h):
    center = (right+left)/2
    if n>center:
        path.append('R')
        left = math.ceil(center)
    else:
        path.append('L')
        right = int(center)

cost = 1
for i in range(len(path)):
    if s[i] != path[i]:
        cost += 2**(h-i)-1+1
        s = s[:i]+s[i+1:]
    else:
        cost += 1
print(cost-1)


h, n = list(map(int, input().split()))
h -= 1
n -= 1
l = 0
r = 2 << h
ll = True
ans = 0
i = 0
while r - l > 1:
    m = (l + r) // 2
    if ll == (n < m):
        ans += 1
    else:
        ans += 1 << (h - i + 1)
    if n < m:
        r = m
        ll = False
    else:
        l = m;
        ll = True
    i += 1
print(ans)


h,n = list(map(int,input().split()))
z = 2
z1 = 1
p = 0
r = 0
h2 = 0
h3 = 2**h
while p < h:
    if n <= h2 +  h3 // z and r == 0:
        z1 += 1
        z *= 2
        r = 1
    elif n > h2 + h3 // z and r == 0:
        h2 += h3 // z
        z1 += 2**(h-p)
        z *= 2
        r = 0
    elif n <= h2 +  h3 // z and r == 1:
        z1 += 2**(h-p)
        z *= 2
        r = 1
    elif n > h2 +  h3 // z and r == 1:
        h2 += h3 // z
        z1 += 1
        z *= 2
        r = 0
    p += 1
print(z1 - 1)


h, n = (int(x) for x in input().split())
leftPlus, rightPlus = 1, 2**h
answer = 1
curLevel = 0
delim = 2**(h - 1)
while curLevel != h:
	h -= 1
	if n <= delim:
		answer += leftPlus
		leftPlus, rightPlus = max(rightPlus // 2, leftPlus // 2), 1
		delim -= 2**(h - 1)
		# print ("L", answer)
	else:
		answer += rightPlus
		leftPlus, rightPlus = 1, max(rightPlus // 2, leftPlus // 2)
		delim += 2**(h - 1)
		# print ("R", answer)	
print (answer - 1)

import math

def is_left_son(num):
    if num == num // 2 * 2:
        return True
    else:
        return False

def bin_search(place, depth):
    answer = ""
    length = 2 ** depth
    while length > 1:
        if place > length / 2:
            answer += "R"
            place -= length / 2
        else:
            answer += "L"
        length = length / 2
    return answer

def traverse(depth, route):
    answer = 0
    cur_vert = 1
    cur_dir = "L"
    while route:
        if route[0] == "R":
            cur_vert = cur_vert * 2 + 1
        else:
            cur_vert = cur_vert * 2
        if cur_dir == route[0]:
            answer += 1
        else:
            answer += 2**depth
        depth -= 1
        route = route[1:]
        cur_dir = "R" if is_left_son(cur_vert) else "L"
    return answer
    
h, n = (int(x) for x in input().split())
amount_visited = 0
cur_pos = 1        
print(traverse(h, bin_search(n, h)))
    





h, n = list(map(int, input().split()))
h += 1

moves = []

result = h - 1

n += (2**(h-1)) - 1

while n != 1:
    if n % 2 == 1:
        moves.append(1)
    else:
        moves.append(0)
    n //= 2

index_on_list = 0

ch = 1

while len(moves) > 0:
    if moves[-1] != index_on_list % 2:
        result += (2**(h-ch)) - 1
    else:
        moves.pop()
        ch += 1

    index_on_list += 1

print(result)





import sys
def main():
    rdl = list(map(int,input().split()))
    obx(rdl[0],rdl[1],0,1)
def obx(lvl, ind, kl, current):
    if lvl ==0:
        print(int(kl))
        return
    all = 0
    for i in range(lvl+1):
        all += 2**i
    all -= 1

    if ind > (2**(lvl))/2:
        if current == 1:
            kl += all / 2 + 1
        else: 
            kl += 1
            current *= -1
        obx(lvl-1,ind-(2**lvl)/2,kl,current)
    else: 
        if current == -1:
            kl += all/2+1
        else: 
            kl += 1
            current *= -1
        obx(lvl-1,ind,kl,current)
        
main()

def main():
	h, n = (list(map(int, input().split())))
	c, m = 0, 2 ** h
	r = 0
	while m > 1:
		if c == 0:
			if n > (m//2):
				r += m - 1
				n -= m//2
				c = 1 - c
		else:
			if n > m//2:
				n -= m//2
			else:
				r += m - 1
				c = 1 - c
		c = 1 - c
		r += 1
		m //= 2
	print(r)




	

def __starting_point():
	main()


__starting_point()

h, n = [int(_) for _ in input().split()]
start = 1
end = 2 ** h
last = "l"
ans = 0
for i in range(h):
    mid = (start + end) // 2
    if n <= mid:
        end = mid
        if last == 'l':
            last = 'r'
            ans += 1
        else:
            ans += 2 ** (h - i)
    else:
        start = mid
        if last == 'r':
            last = 'l'
            ans += 1
        else:
            ans += 2 ** (h - i)

print(ans)


h,n=input().split(' ')
h=int(h)
n=int(n)
s='l'
ans=0
for i in range(h,0,-1):
 if n>pow(2,i-1):
     if s=='l':
       ans+=pow(2,i)
     else:
       ans+=1
     s='l'
     n-=pow(2,i-1)
 else:
     if s=='r':
         ans+=pow(2,i)
     else:
         ans+=1;
     s='r'
print (ans)


def n_of_nodes(h):
    result = 0
    for i in range(h):
        result += 2 ** i
    return result

h, n = tuple(map(int, input().split()))

way = ""
t = h
while t:
    if n % 2:
        way = "L" + way
        n //= 2
        n += 1
    else:
        way = "R" + way
        n //= 2
    t -= 1

answer = 1
current = "L"
t = h
for i in way:
    if i == current:
        answer += 1
        if current == "L":
            current = "R"
        else:
            current = "L"
    else:
        answer += n_of_nodes(t) + 1
    t -= 1

print(answer - 1)


h, n = map(int, input().split())
ans = h
n = n - 1 + (1 << h)
for i in range(1, h+1):
    if not ( ((n & (1 << i)) == 0) ^ (n & (1 << (i-1)) == 0 )):
        ans += (1 << i) - 1
print(ans)