In some other world, today is Christmas.
Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing:
 - A level-0 burger is a patty.
 - A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom.
For example, a level-1 burger and a level-2 burger look like BPPPB and BBPPPBPBPPPBB (rotated 90 degrees), where B and P stands for a bun and a patty.
The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?

-----Constraints-----
 - 1 \leq N \leq 50
 - 1 \leq X \leq ( the total number of layers in a level-N burger )
 - N and X are integers.

-----Input-----
Input is given from Standard Input in the following format:
N X

-----Output-----
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger.

-----Sample Input-----
2 7

-----Sample Output-----
4

There are 4 patties in the bottom-most 7 layers of a level-2 burger (BBPPPBPBPPPBB).

Difficulty: interview

Starter code:

Solutions:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

a,p = [1],[1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    else:
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n-1])

print((f(n, x)))


# レベルLのN番目
def solve(L,N):
    if L == 0:
        return 1
    if N == 1:
        return 0
    elif N <= 2**(L+1)-2:
        return solve(L-1,N-1)
    elif N == int(2**(L+1)-1):
        return 2**L
    return solve(L-1,N-2**(L+1)+1)+2**L
    

N,X = map(int,input().split())
print(solve(N,X))

N,X = map(int,input().split())
siz = [1]
pat = [1]
for i in range(N):
    siz.append(siz[-1]*2 + 3)
    pat.append(pat[-1]*2 + 1)

def rec(n,x):
    if n==0:
        ret = int(x>0)
    elif x <= 1 + siz[n-1]:
        ret = rec(n-1, x-1)
    else:
        ret = pat[n-1] + 1 + rec(n-1, x-2-siz[n-1])
    return ret
print(rec(N,X))

import sys
sys.setrecursionlimit(10**5)
N, X = map(int, input().split())

layers = [1]
patties = [1]

for i in range(1, N+1):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 1 if n == 0 else 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
		
	else:
		return 2 * patties[n-1] + 1
		
print(f(N, X))

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

p = [0] * -~n
l = [0] * -~n

p[0] = 1
l[0] = 1
for i in range(1, n + 1):
    p[i] = p[i - 1] * 2 + 1
    l[i] = l[i - 1] * 2 + 3

# バーガーの長さは奇数


def rec(m, y):
    if y <= 0:
        return 0
    if m == 0:
        return 1
    h = l[m] // 2  # レベルmの半分より左側の長さ
    if h < y:  # 真ん中含む
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    else:
        return rec(m - 1, y - 1)


print((rec(n, x)))


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

p = [0] * -~n
l = [0] * -~n

p[0] = 1
l[0] = 1
for i in range(1, n + 1):
    p[i] = p[i - 1] * 2 + 1
    l[i] = l[i - 1] * 2 + 3

# バーガーの長さは奇数


def rec(m, y):
    if y <= 0:
        return 0
    if m == 0:
        return 1 if y > 0 else 0
    h = l[m] // 2  # レベルmの半分より左側の長さ
    if h < y:  # 真ん中含む
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    else:
        return rec(m - 1, y - 1)


print((rec(n, x)))


import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N, X = NMI()
    A = [1]
    P = [1]
    for i in range(N):
        A.append(A[-1]*2+3)
        P.append(P[-1]*2+1)

    def rec(n, x):
        if n == 0:
            return 1

        if x == 1:
            return 0
        elif x <= A[n-1]+1:
            return rec(n-1, x-1)
        elif x == A[n-1]+2:
            return P[n-1]+1
        elif x <= A[n]-1:
            return P[n-1]+1+rec(n-1, x-A[n-1]-2)
        else:
            return P[n]

    print(rec(N, X))


def __starting_point():
    main()
__starting_point()

n,x=map(int, input().split())
p=[1]*(n+1) #パティ
a=[1]*(n+1) #パティとバンズ

for i in range(1,n+1):
    p[i]=p[i-1]*2+1
    a[i]=a[i-1]*2+3

def f(n,x):
    if x==0:
        return 0
    if n==0:
        return 1
    
    center = a[n-1] + 2
    
    if x < center:
        return f(n-1,x-1)
    elif x >= center:
        return p[n-1] + 1 + f(n-1,x-center)

print(f(n,x))

n,x=map(int,input().split())
l,p=[1],[1]
for i in range(n):
  l+=[l[-1]*2+3]
  p+=[p[-1]*2+1]
x-=1
a=0
while x>0 and n:
  t=l[n]//2
  if x>=t:
    a+=p[n-1]+1
    x-=t
  x-=1
  n-=1
if x>=0 and n==0: a+=1
print(a)

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

def func(m,y):
  if y==0:return 0
  ret=0
  t=4*pow(2,m)-3
  if y>=t-1:
    ret=pow(2,m+1)-1
  elif y==(t-1)//2:
    ret=pow(2,m)-1
  elif y==(t-1)//2+1:
    ret=pow(2,m)
  elif y>(t-1)//2+1:
    ret=pow(2,m)
    ret+=func(m-1,y-(t-1)//2-1)
  else:
    ret=func(m-1,y-1)
  return ret

print(func(n,x))

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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n > 0 and x > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print((ans + (x > 0)))


import sys
sys.setrecursionlimit(100000000)

N,K = map(int,input().split())

store = [pow(2,i+1)-1 for i in range(51)]

def maisu(n):
  return pow(2,n+2)-3

def burger(n,k): #n層でk枚
  if k == maisu(n):
    return store[n]
  elif k <= 1:
    return 0
  elif (maisu(n)-3)//2 +1 >= k:
    return burger(n-1,k-1)
  else:
    #print(k-(2+maisu(n-1)),maisu(n-1))
    return burger(n-1,k-(2+maisu(n-1)))+burger(n-1,maisu(n-1))+1
  
ans = burger(N,K)    
print(ans)

N, X = list(map(int, input().split()))

burger_size = [1]
patty_num = [1]
for i in range(50):
    burger_size.append(2 * burger_size[-1] + 3)
    patty_num.append(2 * patty_num[-1] + 1)


# レベルnバーガーの下からx段目までに含まれるパティの数を返す
def dfs(n, x):
    if burger_size[n] == x:
        return patty_num[n]

    if x == 1:
        return 0

    elif 1 < x <= 1 + burger_size[n - 1]:
        return dfs(n - 1, x - 1)

    elif x == 1 + burger_size[n - 1] + 1:
        return patty_num[n - 1] + 1

    elif 1 + burger_size[n - 1] + 1 < x < burger_size[n]:
        return patty_num[n - 1] + 1 + dfs(n - 1, x - burger_size[n - 1] - 2)


print((dfs(N, X)))


#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

def f(n,x):
    nonlocal h
    if x>2**(n+2)-3:
        x = 2**(n+2)-3
    if (n,x) in h:
        return h[(n,x)]
    ret = -1
    if n==0:
        ret = x
    elif x<=1:
        ret = 0
    elif x<=2**(n+1)-2:
        ret = f(n-1,x-1)
    elif x==2**(n+1)-1:
        ret = 2**n
    elif x<=2**(n+2)-4:
        ret = 2**n+f(n-1,x-2**(n+1)+1)
    else:
        ret = 2**(n+1)-1
    h[(n,x)] = ret
    return ret

n,x = inm()
h = {}
print(f(n,x))


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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print((ans + (x > 0)))


N, X = list(map(int, input().split()))
# a=レベルiバーガーの厚さ, p = レベルiバーガーのパティの数
a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

# レベルNバーガーの下からX層にあるパティの数


def f(N, X):
    if N == 0:
        if X <= 0:
            return 0
        else:
            return 1
    if X == 1:
        return 0
    elif 1 < X <= 1 + a[N - 1]:
        return f(N - 1, X - 1)
    elif X == 2 + a[N - 1]:
        return p[N - 1] + 1
    elif 2 + a[N - 1] < X <= 2 + 2 * a[N - 1]:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
    elif X == 3 + 2 * a[N - 1]:
        return 2 * p[N - 1] + 1

print((f(N, X)))


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, X = LI()
    X -= 1

    # バーガーの厚さ
    l = [0] * (N + 1)
    l[0] = 1
    for i in range(N):
        l[i+1] = 2 * l[i] + 3

    # バーガーのパティ数
    p = [0] * (N + 1)
    p[0] = 1
    for i in range(N):
        p[i+1] = 2 * p[i] + 1

    def rec(n, x):
        if n == 0:
            return 1
        else:
            if x == 0:
                return 0
            elif 1 <= x <= l[n-1]:
                return rec(n - 1, x - 1)
            elif x == l[n-1] + 1:
                return p[n-1] + 1
            elif l[n-1] + 2 <= x <= l[n] - 2:
                return p[n-1] + 1 + rec(n - 1, x - 2 - l[n-1])
            elif x == l[n] - 1:
                return p[n]

    ans = rec(N, X)
    print(ans)

def __starting_point():
    resolve()

__starting_point()

n, x = list(map(int, input().split()))
a, p = [1], [1]
for i in range(n):
    a.append(2*a[-1] + 3)
    p.append(2*p[-1] + 1)

def f(n, x): #レベルnバーガーのｘまでのパティの数
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])

print((f(n, x)))
    
        


# coding: utf-8

# https://atcoder.jp/contests/abc115
# 10:59 giveup


def main():
    N, X = list(map(int, input().split()))

    p = [None] * (N+1)
    p[0] = 1
    for i in range(N):
        p[i+1] = 2*p[i] + 1

    whole = [None] * (N+1)
    whole[0] = 1
    for i in range(N):
        whole[i+1] = 2*whole[i] + 3

    def rec(N, X):
        if N == 0:
            if X == 1:
                return 1
            else:
                return 0

        if X <= 1:
            return 0

        elif X <= 1 + whole[N-1]:
            return rec(N-1, X-1)

        elif X <= 1 + whole[N-1] + 1:
            return p[N-1] + 1

        elif X <= 1 + whole[N-1] + 1 + whole[N-1]:
            return p[N-1] + 1 + rec(N-1, X-(1+whole[N-1]+1))

        else:
            return p[N-1] + 1 + p[N-1]

    ans = rec(N, X)

    return ans


print((main()))


N,X=map(int,input().split())

def n_pati(l):
  val = 1
  for i in range(l):
    val = val*2+1
  return val

def n_layer(l):
  val = 1
  for i in range(l):
    val = val*2+3
  return val

SUM=0
while 1:
  if N==1:
    if X in [0,1]:break
    elif X>=2:
      SUM += min(3,X-1)
      break
  
  L = n_layer(N)
  if X >= L//2:
    SUM += n_pati(N-1)
    X -= n_layer(N-1)+1
    if X==0:
      break
    SUM += 1
    X -= 1
    if X==0:
      break
    N -= 1
  else:
    X -= 1
    N -= 1
    
  if X in [0,1]:break
  
print(SUM)

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

f_dict = {
  0: 1
}
def f(n):
  if f_dict.get(n):
    return f_dict.get(n)
  return (3 + f(n-1) * 2)


patty_dict = {
  0: 1
}
def total_patty(n):
  if patty_dict.get(n):
    return patty_dict.get(n)
  return (1 + 2 * total_patty(n - 1))

def count_patty(n, x):
  if n == 0 and x == 1:
    return 1
  elif x == 0:
    return 0
  elif 1 <= x and x <= f(n - 1) + 1:
    return count_patty(n - 1, x - 1)
  elif x == f(n - 1) + 2:
    return total_patty(n - 1) + 1
  elif f(n - 1) + 2 <= x and x <= 2 * f(n - 1) + 2:
    return total_patty(n - 1) + 1 + count_patty(n - 1, x - f(n - 1) - 2)
  else:
    return total_patty(n)

print(count_patty(n, x))

#!/usr/bin/env python3
def main():
    N, X = list(map(int, input().split()))
    nums = [None] * (N+1)# nums[i]: i次元バーガーの層の数
    pnums = [None] * (N+1)# pnums[i]: i次元バーガーのパティの枚数
    nums[0] = 1
    pnums[0] = 1
    for i in range(N):
        nums[i+1] = nums[i]*2 + 3
        pnums[i+1] = pnums[i]*2 + 1
    
    ans = 0
    while N >= 0:
        if N == 0:
            print((ans+1))
            break
        if X == 1:
            print(ans)
            break
        elif X <= nums[N-1]+1:# N-1次元バーガの中をさらに探索
            X -= 1
            N -= 1
        elif X == nums[N-1]+2:# ぴったり真ん中のパティまで到達
            print((ans+pnums[N-1]+1))
            break
        elif X < nums[N]:
            X -= nums[N-1]+2
            ans += pnums[N-1]+1
            N -= 1
        else:
            print((ans+pnums[N]))
            break
    # print(N,X)

def __starting_point():
    main()

__starting_point()


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

pb=[[0]*2 for i in range(n+1)]
pb[0][0]=1
pb[0][1]=1
for i in range(1,n+1):
    pb[i][0]=3+pb[i-1][0]*2
    pb[i][1]=1+pb[i-1][1]*2

def pbx(xx,nn):
#    print(xx,nn)
    if nn==0:
        return 1
    if xx==1:
        return 0
    elif xx<=1+pb[nn-1][0]:
        return pbx(xx-1,nn-1)
    elif xx==2+pb[nn-1][0]:
        return pb[nn-1][1]+1
    elif xx<=2+pb[nn-1][0]*2:
        xxx=pbx(xx-pb[nn-1][0]-2,nn-1)
#        print("xxx1",xxx)
        xxx=pb[nn-1][1]+1+xxx
#        print("xxx2",xxx)
        return xxx
    elif xx==3+pb[nn-1][0]*2:
        return pb[nn][1]
    else:
        print(("----------",xx,nn))
        return 0

    
print((pbx(x,n)))


ip = input().split(" ")
n = int(ip[0])
x = int(ip[1])

def get_num_layers(level):
    if level == 1:
        return 5
    return 5*(1<<(level-1)) + 3*((1<<(level-1)) - 1)

def func(level, index):
    if level == 1:
        return min(index-1, 3)
    num_layers = get_num_layers(level)
    mid = num_layers//2
    if index == mid+1:
        return 1 + func(level-1,mid-1)
    if index == 1:
        return 0
    if index == num_layers:
        return 2*func(level-1,mid-1) + 1
    if index <= mid:
        return func(level-1,index-1)
    if index > mid+1:
        return 1 + func(level-1,mid-1) + func(level-1,index-mid-1)
    
print((func(n, x)))



N,X=list(map(int,input().split()))
a,p=[1],[1]
for i in range(N):
   a.append(a[i]*2+3)
   p.append(p[i]*2+1)
def ans(N,X):
   if N==0:
      return 0 if X<=0 else 1
   elif X<=1+a[N-1]:
      return ans(N-1,X-1)
   else:
      return p[N-1]+1+ans(N-1,X-2-a[N-1])
print(ans(N,X))

N, X = list(map(int, input().split()))

a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print((f(N, X)))


n, x = map(int, input().split())
a, p = [1], [1]
for i in range(n):
    a.append(2*a[-1] + 3)
    p.append(2*p[-1] + 1)
 
def f(n, x): #レベルnバーガーのｘまでのパティの数
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])
 
print(f(n, x))

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

# レベルnバーガー
def dfs(k):
    nonlocal count, ans
    # バン
    count += 1
    if k == 0:
        ans += 1
    elif count < x:
        # レベルn-1バーガー
        if count + b[k-1] > x:
            dfs(k-1)
        else:
            count += b[k-1]
            ans += p[k-1]
        if count < x:
            # パティ
            count += 1
            ans += 1
            if count < x:
                # レベルn-1バーガー
                if count + b[k-1] > x:
                    dfs(k-1)
                else:
                    count += b[k-1]
                    ans += p[k-1]

n, x = MAP()
b = [0]*n
p = [0]*n
b[0] = 1
p[0] = 1
for i in range(1, n):
    b[i] = b[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1

count = 0
ans = 0
dfs(n)
print(ans)

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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
while n * x > 0:
    if x >= slice[n - 1] + 2:
        ans += pate[n - 1] + 1
        x -= slice[n - 1] + 2
    elif x < slice[n - 1] + 2:
        x -= 1
    n -= 1
print((ans + (x > 0)))


N,X = map(int,input().split())

# レベル0バーガー P
# レベル1バーガー BPPPB
# P[i] = レベルiバーガーのパティの枚数
# B[i] = レベルiバーガーの厚さ

P = [0] * 51
B = [0] * 51

P[0] = 1
B[0] = 1

for i in range(1, len(P)):
  P[i] = P[i - 1] * 2 + 1
  B[i] = B[i - 1] * 2 + 3

# レベルnバーガーを丸ごと食べたときのパティの枚数を求める
def get_whole_barger(n):
  return P[n]

# レベルnバーガーをx枚目まで食べたときのパティの枚数を求める
def get_patty(n,x):
  if n == 0 or x == 0:
    return P[0]
  if B[n] == x:
    return P[n]
  if x <= 1:
    return 0
  if x <= 1 + B[n - 1]:
    return get_patty(n - 1, x - 1)
  if x <= 2 + B[n - 1]:
    return get_whole_barger(n - 1) + 1
  if x <= 2 + B[n - 1] * 2:
    return get_whole_barger(n - 1) + 1 + get_patty(n - 1, x - 2 - B[n - 1])
  else:
    return get_whole_barger(n - 1) + 1 + get_whole_barger(n - 1)

print(get_patty(N,X))

N, X = list(map(int, input().split(' ')))

p = [1]
pb = [1]
np = 0
nx = X

for _ in range(N):
    p.append(p[-1] * 2 + 1)
    pb.append(pb[-1] * 2 + 3)


def dfs(level):
    nonlocal np, nx

    if nx == 0:
        return

    if nx >= pb[level]:
        nx -= pb[level]
        np += p[level]
        return

    nx -= 1
    if nx == 0:
        return

    dfs(level - 1)

    if nx == 0:
        return

    nx -= 1
    np += 1

    if nx == 0:
        return

    dfs(level - 1)

    if nx == 0:
        return

    nx -= 1


dfs(N)

print(np)


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

sizes = [1]

for i in range(n):
    sizes.append(2*sizes[i]+3)

prev = {}

def solve(n, x):
    if (n, x) in prev:
        return prev[(n, x)]
    else:
        if n == 0:
            return 1 if x == 1 else 0
        else:
            ans = 0
            if x == sizes[n]:
                ans = 2*solve(n-1, sizes[n-1]) + 1
            else:
                mid = sizes[n]//2 + 1

                if x == mid:
                    ans = solve(n-1, sizes[n-1]) + 1
                elif x < mid:
                    ans = solve(n-1, x-1)
                else:
                    ans = solve(n-1, sizes[n-1]) + 1 + solve(n-1, x-mid)

            prev[(n, x)] = ans
            return ans

print(solve(n, x))

# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, X):
    layer = [1]
    pate = [1]
    for _ in range(N):
        layer.append(layer[-1] * 2 + 3)
        pate.append(pate[-1] * 2 + 1)

    # print(layer[-1])
    # print(pate[-1])

    def burger(n, l):
        if layer[n] <= l:
            return pate[n]
        if l == 0:
            return 0
        re = 0
        if layer[n] // 2 + 1 <= l:
            re += pate[n - 1] + 1  # center pattie
            l -= layer[n] // 2 + 1
        else:
            l -= 1  # first bun
        re += burger(n - 1, l)
        return re

    print((burger(N, X)))


def __starting_point():
    N, X = list(map(int, input().split()))
    solve(N, X)

    # # test
    # from random import randint
    # from func import random_str
    # N, X = 3, 1
    # for i in range(1, 29 + 1):
    #     solve(N, i)

__starting_point()

# 解説AC
n,x = map(int,input().split())
b,p = [1],[1]
for i in range(n):
    # レベルNバーガーの層の総数
    b.append(b[i] * 2 + 3)
    # レベルNバーガーのPの総数
    p.append(p[i] * 2 + 1)
# 再帰関数でPの総数を調べる
# レベル0バーガーから1,2...Nまでの下からX層のPの総数を順番に調べる
def pate(n,x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1
    elif x <= 1 + b[n-1]:
        return pate(n-1,x-1)
    else:
        return p[n-1] + 1 + pate(n-1,x-2-b[n-1])
print(pate(n,x))

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

pate, slice = [1], [1]
for _ in range(n):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
for i in range(n)[::-1]:
    if x >= slice[i] + 2:
        ans += pate[i] + 1
        x -= slice[i] + 2
    elif x < slice[i] + 2:
        x -= 1
print((ans + (x > 0)))


N,X = map(int,input().split())
lsa = [1]
lsp = [1]
for i in range(50):
    lsa.append(2*lsa[-1]+3)
    lsp.append(2*lsp[-1]+1)

def f(n,x):
    if x == 1:
        return 1 if n==0 else 0
    if 1 < x and x <= 1+lsa[n-1]:
        return f(n-1,x-1)
    if x == 2+lsa[n-1]:
        return lsp[n-1]+1
    if 2 + lsa[n-1] < x and x <= 2+2*lsa[n-1]:
        return lsp[n-1]+1+f(n-1,x-2-lsa[n-1])
    if x == 3+2*lsa[n-1]:
        return 2*lsp[n-1] + 1

print(f(N,X))

def main():
    n, x = map(int, input().split())

    pb = [1]
    p = [1]
    for _ in range(n):
        pb.append(pb[-1] * 2 + 3)
        p.append(p[-1] * 2 + 1)

    ans = 0
    for _ in range(n):
        if x == 0:
            break
        if x >= pb[-2] + 2:
            x -= pb[-2] + 2
            ans += 1 + p[-2]
        else:
            x -= 1
        pb.pop(-1)
        p.pop(-1)

    if x >= 1:
        ans += 1

    print(ans)

main()

#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, X = LI()

"""
Lv i のバーガーの厚みをa[i]
Lv i に含まれるパティの数をp[i]
とすると
a[0] = 1
a[i] = 2 * a[i-1] + 3
p[0] = 1
p[i] = 2 * p[i - 1] + 1

X = 1 f(N, X) = 0

1 < X <= 1 + a[i - 1]
一番したのバン

2 + a[i - 1] < X
一番したのバン　＋　
"""
a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N - 1]:
        return f(N - 1, X - 1)
    else:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
print((f(N, X)))







N, X = map(int, input().split())

burger = [1]
patty = [1]
for i in range(N):
    burger.append(burger[i]*2 + 3)
    patty.append(patty[i]*2 + 1)
    
def f(N, X):
    if N == 0:
        if X <= 0:
            return 0
        else:
            return 1
    elif X <= burger[N-1] + 1:
        return f(N-1, X-1)
    else:
        return patty[N-1] + 1 + f(N-1, X-2-burger[N-1])

ans = f(N, X)
print(ans)

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

def level_n_putty(n):
    if n == 0:
        return 1
    else:
        return 2 * level_n_putty(n-1) + 1

def level_n_hb(n):
    if n == 0:
        return 1
    else:
        return 2 * level_n_hb(n-1) + 3

m = level_n_hb(n)

s = 0
base = 0

while True:
    if x == base + 1:
        if n == 0:
            s += 1
        break
    elif x == base + m:
        s += level_n_putty(n)
        break
    else:
        l = level_n_hb(n-1)
        #print(n, base + l + 2, x)
        if x < base + l + 2:
            base += 1
            n -= 1
            m = l
        elif x == base + l + 2:
            s += 1 + level_n_putty(n-1)
            break
        else:
            base = base + l + 2
            s += 1 + level_n_putty(n-1)
            n -= 1
            m = l

print(s)


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

p = [0] * -~n
l = [0] * -~n

p[0] = 1
l[0] = 1
for i in range(1, n + 1):
    p[i] = p[i - 1] * 2 + 1
    l[i] = l[i - 1] * 2 + 3

# バーガーの長さは奇数


def rec(m, y):
    if y == 0:
        return 0
    if m == 0:
        return 1
    h = l[m] // 2  # レベルmの半分より左側の長さ
    if h < y:  # 真ん中含む
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    else:
        return rec(m - 1, y - 1)


print((rec(n, x)))


n,x = map(int,input().split())
a,p = [1],[1]
for i in range(n):
  a.append(a[i]*2+3)
  p.append(p[i]*2+1)
def f(n,x):
  if n == 0:
    return 0 if x <= 0 else 1
  elif x <= 1 + a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1] + 1 + f(n-1,x-2-a[n-1])
print(f(n,x))

N,X=list(map(int,input().split()))  #S=2**(N+2)-3
                  #P=2**(N+1)-1
def solve(N,X):
    if X==0:
        return 0
    if N==0:
        return X
    if X<2**(N+1)-1:
        return solve(N-1,X-1)
    elif X==2**(N+1)-1:
        return 2**N
    elif X<2**(N+2)-3:
        return 2**N+solve(N-1,X-2**(N+1)+1)
    else:
        return 2**(N+1)-1

print((solve(N,X)))


N, X = map(int, input().split())

ans = 0
for i in range(N, -1, -1):
    if X < 2**(i + 1) - 1:
        X -= 1
    elif X > 2 ** (i + 1) - 1:
        X -= 2 ** (i + 1) - 1
        ans += 2 ** i
    else:
        ans += 2 ** i
        break
    if X == 0:
        break
    #print(X, ans)


print(ans)

N, X = map(int, input().split())

Total = [1]
Patties = [1]

for i in range (1, N+1):
	Total.append(Total[i-1]*2+3)
	Patties.append(Patties[i-1]*2+1)

def Burger(N,X):
	if N== 0:
		if X <= 0:
			return (0)
		else:
			return (1)
	elif X <= 1+Total[N-1]:
		return Burger(N-1, X-1)
	else:
		return Patties[N-1]+1+Burger(N-1, X-2-Total[N-1])

print(Burger(N,X))

3
#coding: utf-8

from collections import defaultdict

N, X = (int(x) for x in input().split())

memo = {}

def size_lv(lv):
    if lv == 0:
        return 1
    if lv not in memo:
        memo[lv] = size_lv(lv-1) * 2 + 3
    return memo[lv]

memo2 = {}
def num_pty(lv, X):
    if (lv, X) in memo2:
        return memo2[(lv, X)]
    if X == 0:
        return 0

    if lv == 0:
        memo2[(lv, X)] = 1
        return memo2[(lv, X)]

    prevSize = size_lv(lv-1)
    if X <= prevSize+1:
        memo2[(lv, X)] = num_pty(lv-1, X-1)
        return memo2[(lv, X)]
    
    if X == prevSize + 2:
        memo2[(lv, X)] = num_pty(lv-1, prevSize) + 1
        return memo2[(lv, X)]
    
    memo2[(lv, X)] = num_pty(lv-1, prevSize) + 1 + num_pty(lv-1, min(X-prevSize-2, prevSize))
    return memo2[(lv, X)]
    
print((num_pty(N, X)))

# BBPPPBPBPPPBB
# BPPPB


import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,X=mi()

    def solve(n,x):
        # print(n,x)
        if n == 0: return 1
        c = 2**(n+2)-3
        half = c//2

        res = 0
        if x <= half:
            if x == 1:
                res += 0
            else:
                res += solve(n-1,x-1)
        elif x == half+1:
            res += 2**(n-1+1) - 1 + 1
        elif x < c:
            res += 2**(n-1+1) - 1 + 1 + solve(n-1,x-(half+1))
        else:
            assert x == c
            res += 2**(n+1)-1

        return res

    print(solve(N,X))



def __starting_point():
    main()
__starting_point()

# 初期入力
import sys
input = sys.stdin.readline
N,X = (int(i) for i in input().split())
DP_all  =[0]*(N+1)
DP_p    =[0]*(N+1)
DP_all[0]   =1
DP_p[0]     =1

#レベル「i+1」バーガーの枚数
for i in range(N):
    DP_all[i+1] =DP_all[i] *2 +3
    DP_p[i+1]   =DP_p[i] *2  +1
#print("総枚数" ,DP_all)
#print("パティ枚数" ,DP_p)

#再帰でパティの枚数を求める L=レベル、x=食べる枚数
def  p_num(L,x):
    if x <=L:
        return 0
    if x ==DP_all[L]:
        return DP_p[L]
    elif x < DP_all[L] //2 +1:
        return p_num(L-1,x -1)
    elif x ==DP_all[L] //2 +1:
        return DP_p[L-1] +1
    elif x > DP_all[L] //2 +1:
        return DP_p[L-1] +1 +p_num(L-1,x -DP_all[L-1] -2)

ans =p_num(N,X)
print(ans)

N, K = map(int, input().split())

L = [1]
P = [1]

for i in range(N):
    L.append(L[i] * 2 + 3)
    P.append(P[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + L[N-1]:
        return f(N-1, X-1)
    else:
        return P[N-1] + 1 + f(N-1, X-2-L[N-1])

print(f(N, K))

import sys
sys.setrecursionlimit(10 ** 6)

N, X = list(map(int, input().split()))

h = [1]
p = [1]

for _ in range(50):
    h.append(h[-1] * 2 + 3)
    p.append(p[-1] * 2 + 1)

def bug(l, y):
    if l == 0:
        return 0 if y <= 0 else 1
    
    mid = (h[l] + 1) // 2
    if y < mid:
        return bug(l - 1, y - 1)
    elif y == mid:
        return p[l - 1] + 1
    elif y > mid:
        return p[l - 1] + 1 + bug(l - 1, y - mid)
    
print((bug(N, X)))


N,X=map(int,input().split())
A=[1]*(N+1)
P=[1]*(N+1)
for i in range(1,N+1):
    P[i]=2*P[i-1]+1
    A[i]=2*P[i]-1

def f(N,X):
    if X==1:
        if N==0:
            return 1
        else:
            return 0
    elif 1<X<=1+A[N-1]:
        return f(N-1,X-1)
    elif X==2+A[N-1]:
        return P[N-1]+1
    elif 2+A[N-1]<X<=2+2*A[N-1]:
        return P[N-1]+1+f(N-1,X-2-A[N-1])
    else:
        return 2*P[N-1]+1

print(f(N,X))

#create date: 2020-07-01 09:01

import sys
stdin = sys.stdin
from functools import lru_cache

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

@lru_cache(maxsize=2**52-3)
def f(n, x):
    if n == 0:
        return 1

    if x == 1:
        return 0
    elif x <= 2**(n+1)-2:
        #print("f({}, {})".format(n-1, x-1))
        return f(n-1, x-1)
    elif x == 2**(n+1)-1:
        return f(n-1, 2**(n+1)-3) + 1
    elif x < 2**(n+2)-2:
        return f(n-1, 2**(n+1)-3) + 1 + f(n-1, x-(2**(n+1)-1))
    else:
        return 2 * f(n-1, 2**(n+1)-3) + 1

def main():
    n, x = na()
    print(f(n, x))


def __starting_point():
    main()
__starting_point()


        
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    def f(n, x):
        if n == 0:
            return 0 if x<=0 else 1
        elif x <= a[n-1]+1:
            return f(n-1, x-1)
        else:
            return p[n-1]+1+f(n-1, x-2-a[n-1])

    n, x = map(int, input().split())
    a, p = [1], [1]
    for i in range(n):
        a.append(2*a[-1]+3)
        p.append(2*p[-1]+1)
    print(f(n, x))





                
def __starting_point():
    main()
__starting_point()

n, x = list(map(int, input().split()))
p = [1] * -~n
l = [1] * -~n
for i in range(1, n + 1):
    p[i] = p[i - 1] * 2 + 1
    l[i] = l[i - 1] * 2 + 3

def rec(m, y):
    if y == 0:
        return 0
    if m == 0:
        return 1
    h = l[m] // 2
    if h < y:
        return 1 + p[m - 1] + rec(m - 1, y - h - 1)
    else:
        return rec(m - 1, y - 1)
print((rec(n, x)))


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

pate, slice = [1], [1]
for _ in range(n + 1):
    pate.append(2 * pate[-1] + 1)
    slice.append(2 * slice[-1] + 3)

ans = 0
for i in range(n)[::-1]:
    if x >= slice[i] + 2:
        ans += pate[i] + 1
        x -= slice[i] + 2
    elif x < slice[i] + 2:
        x -= 1
print((ans + (x > 0)))


import sys
sys.setrecursionlimit(10**5)
N, X = map(int,input().split())
l = [1]
for i in range(N):
    l.append(2*l[-1]+3)
d = {}
def f(n,x):
    if (n,x) in d:
        return d[(n,x)]
    if n == 0:
        ans = 1
    elif x == 1:
        ans = 0
    elif x <= l[n-1]+1:
        ans = f(n-1,x-1)
    elif x == l[n-1]+2:
        ans = f(n-1,l[n-1])+1
    elif x <= 2*l[n-1]+2:
        ans = f(n-1, l[n-1])+1+f(n-1, x-l[n-1]-2)
    else:
        ans = 2*f(n-1, l[n-1])+1
    d[(n,x)] = ans
    return ans
print(f(N, X))

n, x = list(map(int,input().split()))
a = [1]
p = [1]

for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    median = (a[n]+1)//2

    if x < median:
        return f(n-1, x-1)
    elif x == median:
        return p[n-1] + 1
    else:
        return p[n-1] + 1 + f(n-1, x - median)

print((f(n,x)))


n,x=map(int,input().split())
patty=[1]
barger=[1]
ans=0
for i in range(n):
  patty.append(2*patty[-1]+1)
  barger.append(2*barger[-1]+3)
i=n
while x>0:
  for _ in range(n):
    if x>=barger[i]:
      x-=barger[i]
      ans+=patty[i]
      if x>0:
        ans+=1
        x-=1
      break
    i-=1
    x-=1
print(ans)

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

#lレベルバーガーの下からx層に含まれるパティーの数
a=[1]*(n+1)
p=[1]*(n+1)
for i in range(1,n+1):
  a[i]=a[i-1]*2+3
  p[i]=p[i-1]*2+1

def count(l,x):
  if l==0:
    if x>=1:
      return 1
    else:
      return 0
  else:
    if x==1:
      return 0
    elif x<a[l-1]+2:
      return count(l-1,x-1)
    elif x==a[l-1]+2:
      return p[l-1]+1
    elif a[l]>x:
      return count(l-1,x-a[l-1]-2)+p[l-1]+1
    else:
      return p[l]
    
print((count(n,x)))    


def solve():
    n, x = list(map(int, input().split()))
    l = [1]
    nu = [1]
    for i in range(n):
        l.append(l[-1] * 2 + 3)
        nu.append(nu[-1] * 2 + 1)

    def chris(a, b):
        if a == 0:
            return b
        elif b <= a:
            return 0
        hl = l[a]
        if b >= hl - a:
            return nu[a]
        elif hl // 2 + 1 <= b:
            return nu[a - 1] + 1 + chris(a - 1, b - (hl // 2 + 1))
        return chris(a - 1, b - 1)

    print((chris(n, x)))


solve()


n,x=map(int,input().split())
l,p=[1],[1]
for i in range(n):
  l+=[l[-1]*2+3]
  p+=[p[-1]*2+1]
x-=1
a=1
while n:
  t=l[n]//2
  if x>=t:
    a+=p[n-1]+1
    x-=t
  x-=1
  n-=1
if x<0: a-=1
print(a)

N,X = map(int, input().split())
burger = [(1,0)]
prev = (1,0)
for i in range(N):
    burger.append((2*prev[0]+1, 2*prev[1]+2))
    prev = burger[-1]

lev = N
cur = X-1
ps = 0
for i in range(N+1):
    if lev == 0:
        ps += 1
        break

    if cur == 0:
        break
    elif cur == sum(burger[lev-1])+1:
        ps += burger[lev-1][0]+1
        break
    elif cur == sum(burger[lev])-1:
        ps += 2*burger[lev-1][0] + 1
        break

    if cur < sum(burger[lev])/2:
        cur -= 1
        lev -= 1
    else:
        ps += burger[lev-1][0] + 1
        cur -= sum(burger[lev-1]) + 2
        lev -= 1
print(ps)

a = [1]
b = [1]
for _ in range(50):
    a.append(2 * a[-1] + 3)
    b.append(2 * b[-1] + 1)

def num_of_patties(n, x):
    if n == 0:
        return 1

    if x == 1:
        return 0
    elif x <= a[n-1] + 1:
        return num_of_patties(n-1, x-1)
    elif x == a[n-1] + 2:
        return b[n-1] + 1
    elif x <= 2 * a[n-1] + 2:
        return b[n-1] + 1 + num_of_patties(n-1, x-a[n-1]-2)
    else:
        return b[n]


print((num_of_patties(*[int(i) for i in input().split()])))


import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return list(map(int, input().split()))
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N,X = i_map()
    a,p = [1],[1]
    for i in range(N):
        a.append(a[i]*2 + 3)
        p.append(p[i]*2 + 1)
    
    def f(N,X):
        if N == 0:
            return 0 if X <= 0 else 1
        elif X <= 1 + a[N-1]:
            return f(N-1, X-1)
        else:
            return p[N-1] + 1 + f(N-1, X-2-a[N-1])
    
    print((f(N,X)))

 

def __starting_point():
    main()


__starting_point()

N, X = list(map(int, input().split()))
a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

# print(a, p)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= a[N-1]+1:
        #端のバンズを消すのでXから1引く
        return f(N-1, X-1)
    else:
        #N-1層のパティ数＋真ん中のパティ＋... X-2-a[i]は追加したBPと下側のN-1層の分を引く
        return p[N-1]+1+f(N-1, X-2-a[N-1])
print((f(N, X)))


N,X = list(map(int,input().split()))
a=[1]
p=[1]
for i in range(1,N+1):
    a.append(a[i-1]*2+3)
    p.append(p[i-1]*2+1)
    
def f(n,x):#レベルnのハンバーガーをx段食べる
    if n ==0:#0段目の終了条件
        return 0 if x <=0 else 1

    if x <= 1+a[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1]+1+f(n-1,x-2-a[n-1])

print((f(N,X)))


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

a, b = [1], [1]

for i in range(n):
    a.append(a[i]*2+3)
    b.append(b[i]*2+1)

def cal(n, x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1
    val = (a[n]+1)//2

    if x < val:
        return cal(n-1, x-1)
    elif x == val:
        return b[n-1]+1
    elif x > val:
        return b[n-1]+1+cal(n-1, x-val)

ans = cal(n, x)
print(ans)
    
    




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

dp = [1]*(n+1)
res = 0

for i in range(1,n+1):
    dp[i] = dp[i-1]*2+3

for j in range(n,1,-1):
    if dp[j] ==x:
        res += (dp[j]+1) //2
        x =0        
    elif dp[j-1]+2 <= x :
        res += 1 + (dp[j-1]+1)//2
        x -= dp[j-1]+2
    elif dp[j-1]+1 ==x:
        res += (dp[j-1]+1)//2
        x = 0
    else:
        x -=1
    
    if x ==0:
        break
        
if x ==5:
    res += 3
elif x ==0:
    pass
else:
    res +=x-1

print(res)


def f(L, x):
    if L == 0:
        return 0 if x <= 0 else 1
    if x <= total[L - 1] + 1:
        return f(L - 1, x - 1)
    else:
        return patties[L - 1] + 1 + f(L - 1, x - total[L - 1] - 2)


N, X = list(map(int, input().split()))
total = [1]
patties = [1]
for i in range(50):
    total.append(total[-1] * 2 + 3)
    patties.append(patties[-1] * 2 + 1)
print((f(N, X)))


N, X = list(map(int, input().split(' ')))

level2p = [1] * (N + 1)
level2pb = [1] * (N + 1)

for i in range(N):
    level2p[i + 1] = level2p[i] * 2 + 1
    level2pb[i + 1] = level2pb[i] * 2 + 3


def dfs(n, x):
    if n == 0:
        return 1

    if x <= 1:
        return 0
    elif x <= 1 + level2pb[n - 1]:
        return dfs(n - 1, x - 1)
    elif x <= 1 + level2pb[n - 1] + 1:
        return level2p[n - 1] + 1
    elif x <= 1 + level2pb[n - 1] + 1 + level2pb[n - 1]:
        return level2p[n - 1] + 1 + dfs(n - 1, x - 1 - level2pb[n - 1] - 1)
    else:
        return level2p[n]


print((dfs(N, X)))


n, x = map(int, input().split())
burger = [2 ** (i + 2) - 3 for i in range(n)]
burger2 = [2 ** (i + 1) - 1 for i in range(n)]
num = [0 for i in range(n)]
ans = 0
temp = n - 1
while x > 0:
    if x >= 1:
        x -= 1
    else:
        continue
    if x >= burger[temp]:
        num[temp] += 1
        x -= burger[temp]
    else:
        temp -= 1
        continue
    if x >= 1:
        ans += 1
        x -= 1
    else:
        continue
    if x >= burger[temp]:
        num[temp] += 1
        x -= burger[temp]
    else:
        temp -= 1
        continue
    if x >= 1:
        x -= 1
    else:
        continue
for i in range(n):
    ans += burger2[i] * num[i]
print(ans)

N,X=map(int,input().split())
L=[[1,1] for _ in range(N+1)]
i=0
while i+1<=N:
    L[i+1][0]=L[i][0]*2+1
    L[i+1][1]=L[i+1][0]*2-1
    i+=1

xx=[[1,1,1,1,1]for _ in range(N+1)]
i=0
while i+1<=N:
    xx[i+1][1]=L[i][1]+1
    xx[i+1][2]=L[i][1]+2
    xx[i+1][3]=2*L[i][1]+2
    xx[i+1][4]=2*L[i][1]+3
    i+=1

ans=0
while N>0:
    if xx[N][0]==X:
        break
    elif xx[N][1]>=X:
        N-=1
        X-=1
    elif xx[N][2]==X:
        ans+=1+L[N-1][0]
        break
    elif xx[N][3]>=X:
        ans+=1+L[N-1][0]
        X-=xx[N][2]
        N-=1
    else:
        ans+=1+2*L[N-1][0]
        break
    if N==0:
        ans+=1

print(ans)

n,x = map(int,input().split())
ans = 0
i = n
while i >= 0:
    c = 2**(i+1) - 3
    num_p = 2**i - 1
    
    if 2*c + 3 == x:
        ans += 2*num_p + 1
        break
    elif c + 2 == x:
        ans += num_p + 1
        break
    elif 1 == x:
        break
    
    elif 2 + c <= x:
        x -= 2 + c
        ans += num_p + 1
    else:
        x -= 1
    
    i -= 1

print(ans)

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

a, p = [1], [1]

for i in range(n):
  a.append(a[i]*2 + 3)
  p.append(p[i]*2 + 1)

def f(n, x):
  if n == 0:
    return 0 if x <= 0 else 1
  elif x <= 1 + a[n-1]:
    return f(n-1, x-1)
  else:
    return p[n-1] + 1 + f(n-1, x-2-a[n-1])

print (f(n,x))

#再帰の深さが1000を超えそうなときはこれをやっておく
import sys
sys.setrecursionlimit(10**7)

n,x=map(int,input().split())
a=[0]*(n+1)
p=[0]*(n+1)
a[0]=1
p[0]=1
for i in range(n):
  a[i+1]=2*a[i]+3
  p[i+1]=2*p[i]+1
  
def func(i,x):
  if i==0:
    if x<=0:
      return 0
    elif x>=1:
      return 1
  mid=(a[i]+1)//2
  if mid==x:
    return p[i-1]+1
  elif mid>x:
    return func(i-1,x-1)
  else:
    return p[i-1]+1+func(i-1,x-mid)


print(func(n,x))  

n,x=map(int,input().split())
a=[1]#層の数 a[n]はレベルnのときの層の数
p=[1]#パテの数　p[n]はレベルnのときのパテの数
for i in range(n):
    a.append(2*a[-1]+3)
    p.append(a[-1]//2 +1)
#print(a,p)
def f(n,x):
    #print(n,x)
    if n==0:
        if x>=1:
            return 1
        else:
            return 0
    elif x==1:
        return 0
    elif x==a[n]:#レベルn全部取る場合
        return p[n]
    elif x==a[n-1]+2:#レベルnの真ん中まで取る場合
        return p[n-1]+1
    elif 1<x<a[n-1]+2:
        return f(n-1,x-1)#再帰関数。行列の2番目～真ん中の1個手前まで、つまりレベルn-1バーガーに移行。レベルnバーガーの最初は飛ばすので、xも-1する。
    else:
        return p[n-1]+1+f(n-1,x-a[n-1]-2)#再帰関数。行列真ん中の次～ラストの手前まで
print(f(n,x))

N, X = list(map(int, input().split()))

size = [1]
patty = [1]
for i in range(N):
    size.append(size[i]*2 + 3)
    patty.append(patty[i]*2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= size[N-1] + 1:
        return f(N-1, X-1)
    elif X == size[N-1] + 2:
        return patty[N-1] + 1
    elif X >= size[N-1] + 3:
        return patty[N-1] + 1 + f(N-1, X-size[N-1]-2)
print((f(N,X)))


N, X = map(int, input().split())
a,p=[1],[1]
for i in range(N):
  a.append(a[i] * 2 + 3) 
  p.append(p[i] * 2 + 1)

def f(N,X):
  if N == 0:
    return 0 if X <= 0 else 1 
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1) 
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

import sys
sys.setrecursionlimit(10**6)

def rec(level, x):
    # print(level,x)
    l_len = pow(2,level+2)-3
    l_len_1 = pow(2,level+1)-3
    num = pow(2,level+1)-1
    num_1 = pow(2,level)-1
    # if level == -2: return
    if level == 0: return 1
    if x == 0: return 0
    if x == 1: return 0
    if x <= l_len_1+1: return rec(level-1,x-1)
    if x <= l_len_1+2: return num_1 + 1
    if x <= l_len-1: return num_1+1 + rec(level-1, x-l_len_1-2)
    else: return num

    # if x == l_len: return num
    # if x <= (l_len-1)//2: return rec(level-1,x-1)
    # if x == (l_len-1)//2+1: return num_1+1
    # else: return num_1+1 + rec(level-1, x-((l_len-1)//2+1))


def main():
    n,x = map(int, input().split())
    print(rec(n,x))

def __starting_point():
    main()
__starting_point()

N,X = map(int,input().split())

def f(N,X):
  if N==0:
    return 0 if X<=0 else 1
  elif X<=1+2**(N+1)-3:
    return f(N-1,X-1)
  else:
    return 2**(N)+f(N-1,X-2**(N+1)+3-2)
        
print(f(N,X))

N, X = list(map(int, input().split()))
L = [1 for _ in range(N+1)]
S = [1 for _ in range(N+1)]
for n in range(1, N+1):
    L[n] = L[n-1] * 2 + 3
    S[n] = S[n-1] * 2 + 1

def rec(level, K):
    if level == 0:
        return 1
    if K == 1:
        return 0
    elif K <= L[level-1] + 1:
        return rec(level-1, K-1)
    elif K == L[level-1] + 2:
        return S[level-1] + 1
    elif K <= L[level-1] * 2 + 2:
        return rec(level-1, K - L[level-1] - 2) + S[level-1] + 1;
    else:
        return S[level-1] * 2 + 1

print((rec(N, X)))


n,x= map(int,input().split())
tp=0
for i in range(n):
    ct = (2**(n-i+2)-4)//2+1
    if x==0:break
    if i==n-1:tp+='bpppb'[:x].count('p')
    else:
        pn = 2**(n-i)-1
        if x<ct:x-=1
        elif x>=ct:
            tp+=pn+1
            if x==ct:break
            x-=ct
print(tp)

N, X = map(int, input().split())
l = [1]
for i in range(N):
  l.append(2*l[-1]+1)

def main(n, x, ans):
  nonlocal X
  nonlocal l
  if n == 0:
    return ans+1
  elif x==1:
    return ans
  elif x==2*l[n]-1:
    return ans+2*l[n-1]+1
  elif x == l[n]:
    return main(n-1, x-2, ans+1)
  elif x < l[n]:
    return main(n-1, x-1, ans)
  else:
    return main(n-1, x-2*l[n-1]-1, ans+l[n-1]+1)
  
a = main(N, X, 0)
print(a)

n, x = list(map(int, input().split()))
b = 1
p = 1
for i in range(n):
    b = 2 * b + 3
    p = 2 * p + 1
x -= 1
b -= 1
ans = 0
while True:
    if x == 0:
        if b == 0:
            ans += 1
        break
    elif x == b:
        ans += p
        break
    elif x == b // 2:
        ans += p // 2 + 1
        break
    elif 0 < x < b // 2:
        x -= 1
    else:
        x -= b // 2 + 1
        ans += p // 2 + 1
    b = (b - 3) // 2
    p = (p - 1) // 2
print(ans)


N,X = list(map(int,input().split()))

burgerLengthList = [[] for i in range(51)]
for i in range(51):
    burgerLengthList[i].append(2 ** (i + 2) - 3)
    burgerLengthList[i].append(2 ** (i + 1) - 1)

def pNumber(level, number):
    if level == 0:
        return 1
    if number == 1:
        return 0
    if number <= burgerLengthList[level][0] // 2:
        return pNumber(level - 1, number - 1)
    elif number == burgerLengthList[level][0] // 2 + 1:
        return pNumber(level - 1, number - 1) + 1
    else:
        return burgerLengthList[level - 1][1] + 1 + pNumber(level - 1, number - burgerLengthList[level - 1][0] - 2)

print(pNumber(N, X))

def delete_head_zeros(n):
	n = str(n)
	l = len(n)
	if "." in n:
		l = n.find(".")
	head_zeros = 0
	for i in range(l - 1):
		if n[i] == "0":
			head_zeros += 1
		else:
			break

	return n[head_zeros:]

# compare a, b
# a, b: int or string
def bigint_compare(a, b):
	a = delete_head_zeros(a)
	b = delete_head_zeros(b)
	if len(a) > len(b):
		return 1
	elif len(a) < len(b):
		return -1
	else:
		if a > b:
			return 1
		elif a < b:
			return -1
		else:
			return 0

# calculate a + b
# a, b: int or string
def bigint_plus(a, b):
	a = str(a)
	b = str(b)

	d = max([len(a), len(b)])
	a = '0' * (d - len(a)) + a
	b = '0' * (d - len(b)) + b

	ans = ""
	carry = 0
	for i in range(d):
		s = int(a[-i-1]) + int(b[-i-1]) + carry
		carry = s // 10
		ans = str(s % 10) + ans
	else:
		if carry:
			ans = str(carry) + ans

	return ans

# calculate a - b
# a, b: int or string
def bigint_minus(a, b): 
	a = str(a)
	b = str(b)
	M = []
	m = []
	sign = ""

	if len(a) > len(b) or (len(a) == len(b) and a >= b):
		[M, m] = [a, b]
	else:
		[M, m] = [b, a]
		sign = "-"
	m = '0' * (len(M) - len(m)) + m

	ans = ""
	borrow = 0
	for i in range(len(M)):
		s = int(M[-i-1]) - int(m[-i-1]) - borrow
		if s < 0:
			borrow = 1
			s += 10
		else:
			borrow = 0
		ans = str(s) + ans

	return sign + delete_head_zeros(ans)

# calculate a * b
# a, b: int or string
def bigint_multiply(a, b):
	a = str(a)
	b = str(b)

	md = []
	for j in range(len(b)):
		carry = 0
		mj = ""
		for i in range(len(a)):
			m = int(a[-i-1]) * int(b[-j-1]) + carry
			carry = m // 10
			mj = str(m % 10) + mj
		else:
			if carry:
				mj = str(carry) + mj
		md.append(mj)

	ans = 0
	for k in range(len(md)):
		ans = bigint_plus(md[k] + "0" * k, ans)

	return ans


# calculate a / b to d digits after decimal point
# a, b, d: int or string
def bigint_divide(a, b, d = 0):
	a = str(a)
	b = str(b)
	d = int(d)
	if d < 0:
		d = 0

	ans = ""
	r = ""
	for i in range(len(a) + d):
		q = 0
		if i < len(a):
			r += a[i]
		elif i == len(a):
			ans += "."
			r += "0"
		else:
			r += "0"

		if bigint_compare(r, b) == -1:
			ans += str(q)
		else:
			while bigint_compare(r, b) >= 0:
				r = bigint_minus(r, b)
				q += 1
			ans += str(q)

	return delete_head_zeros(ans)

def main():
	N, X = input().split(" ")
	layer = [1]
	patties = [1]
	for i in range(int(N)):
		layer.append(bigint_plus(bigint_multiply(layer[-1], 2), 3))
		patties.append(bigint_plus(bigint_multiply(patties[-1], 2), 1))

	def count_patty(L, Y, P): # Y, P : bigint
		if L == 0:
			return bigint_plus(P, 1)
		center = bigint_divide(bigint_plus(layer[L], 1), 2)
		if Y == "1":
			return P
		elif Y == layer[L]:
			return bigint_plus(P, patties[L])
		elif bigint_compare(Y, center) == 0:
			return bigint_plus(bigint_plus(P, 1), patties[L - 1])
		elif bigint_compare(Y, center) == 1:
			return count_patty(L - 1, bigint_minus(Y, center), bigint_plus(bigint_plus(P, patties[L - 1]), 1))
		elif bigint_compare(Y, center) == -1:
			return count_patty(L - 1, bigint_minus(Y, 1), P)

	print(count_patty(int(N), X, "0"))

main()

N, X=map(int, input().split())

def A(x):
  return pow(2, x+2)-3

def P(x):
  return pow(2, x+1)-1

def f(n, x):
  if n==0:
    return 1
  if n==1:
    return min(x-1, 3)
  if x<=n:
    return 0
  if A(n)//2+1==x:
    return P(n-1)+1
  if A(n)==x:
    return P(n)
  if A(n)//2>=x:
    return f(n-1, x-1)
  return P(n-1)+1+f(n-1, x-A(n)//2-1)

print(f(N, X))

import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X = list(map(int, readline().split()))

    A = [0] * (N + 1)
    B = [0] * (N + 1)
    A[0] = B[0] = 1
    for i in range(N):
        A[i + 1] = 2 * A[i] + 3
        B[i + 1] = 2 * B[i] + 1

    def rec(i, x):
        if i == 0:
            return 1 if x > 0 else 0
        elif x <= 1 + A[i - 1]:
            return rec(i - 1, x - 1)
        else:
            return B[i - 1] + 1 + rec(i - 1, x - 2 - A[i - 1])

    print((rec(N, X)))
    return


def __starting_point():
    main()

__starting_point()

from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

# レベルnバーガー
def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])

n, x = MAP()
a = [0]*n
p = [0]*n
a[0] = 1
p[0] = 1
for i in range(1, n):
    a[i] = a[i-1]*2 + 3
    p[i] = p[i-1]*2 + 1

print(f(n, x))

import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return list(map(int,input().split()))
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

N, X = list(map(int, input().split()))
a,p=[1],[1]
for i in range(N):
  a.append(a[i] * 2 + 3) 
  p.append(p[i] * 2 + 1)

def f(N,X):
  if N == 0:
    return 0 if X <= 0 else 1 
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1) 
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print((f(N, X)))



def resolve():
    N, X = map(int, input().split())

    As = [1]  # レベルiバーガーの厚さ（層の総数）（必ず奇数）
    Ps = [1]  # レベルiバーガーのパティの総数

    for i in range(N):
        As.append(As[i] * 2 + 3)  # レベルが1上がると、総数は2倍+3になる
        Ps.append(Ps[i] * 2 + 1)  # レベルが1上がると、パティの数は2倍+1になる

    def f(n, x):
        if n == 0:
            return 0 if x <= 0 else 1
        mid = (As[n] + 1) // 2

        # バーガーの真ん中にはパティがある。そのパティを含むかの場合分けをする
        if x < mid:
            return f(n - 1, x - 1)
        elif x == mid:
            return Ps[n - 1] + 1
        elif x > mid:
            return Ps[n - 1] + 1 + f(n - 1, x - mid)

    ans = f(N, X)

    print(ans)


def __starting_point():
    resolve()
__starting_point()

import sys
from functools import lru_cache

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, X = list(map(int, readline().split()))

    @lru_cache(maxsize=None)
    def rec1(i):
        if i == 0:
            return 1
        else:
            return 2 * rec1(i - 1) + 1

    @lru_cache(maxsize=None)
    def rec2(i):
        if i == 0:
            return 1
        else:
            return 2 * rec2(i - 1) + 3

    def rec(i, x):
        if x <= 0:
            return 0
        if i == 0:
            return 1

        x -= 1
        ans = 0
        if x > rec2(i - 1):
            x -= rec2(i - 1)
            ans += rec1(i - 1)
        else:
            ans += rec(i - 1, x)
            return ans

        if x > 0:
            x -= 1
            ans += 1
        else:
            return ans

        if x > rec2(i - 1):
            x -= rec2(i - 1)
            ans += rec1(i - 1)
        else:
            ans += rec(i - 1, x)

        return ans

    print((rec(N, X)))
    return


def __starting_point():
    main()

__starting_point()