#再帰の深さが1000を超えそうなときはこれをやっておく

import sys

sys.setrecursionlimit(10**7)



n,x=list(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=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)))    

    
# 再帰の深さが1000を超えそうなときはこれをやっておく
import sys

sys.setrecursionlimit(10**7)
n, x = list(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 = 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)))

-# 再帰の深さが1000を超えそうなときはこれをやっておく -import sys - -sys.setrecursionlimit(10**7) -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 +# 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 func(i, x): -    if i == 0: -        if x <= 0: +def count(l, x): +    if l == 0: +        if x >= 1: +            return 1 +        else: -        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) -        return p[i - 1] + 1 + func(i - 1, x - mid) +        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((func(n, x))) +print((count(n, x)))