from functools import lru_cache



@lru_cache()

def f(n):

    if n==0:

        return 1

    return 2*f(n-1)+1



@lru_cache()

def g(n):

    if n==0:

        return 1

    return 2*g(n-1)+3



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

total = [g(i) for i in range(N+1)]

p = [f(i) for i in range(N+1)]

ans = 0



def search(x, n):

    global ans

    if n==0:

        if x:

            ans += 1

        return

    if x==0:

        return

    if x > total[n-1] + 2:

        ans += p[n-1] + 1

        search(x-(2 + total[n-1]), n-1)

    elif x == total[n-1] + 2:

        ans += p[n-1] + 1

    else:

        search(x-1, n-1)



search(X, N)

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

q = [1]*(N+1)

p = [1]*(N+1)

for i in range(1, N+1):

    q[i] = 2*q[i-1]+3

    p[i] = 2*p[i-1]+1



ans = 0

def search(x, n):

    global ans

    if n==0:

        if x:

            ans += 1

        return

    if x==0:

        return

    

    a = q[n-1] + 2

    b = p[n-1] + 1



    if x > a:

        ans += b

        search(x-a, n-1)

    elif x == a:

        ans += b

    else:

        search(x-1, n-1)



search(X, N)

print(ans)
from functools import lru_cache


@lru_cache()
def f(n):
    if n == 0:
        return 1
    return 2 * f(n - 1) + 1


@lru_cache()
def g(n):
    if n == 0:
        return 1
    return 2 * g(n - 1) + 3


N, X = list(map(int, input().split()))
total = [g(i) for i in range(N + 1)]
p = [f(i) for i in range(N + 1)]
ans = 0


def search(x, n):
    global ans
    if n == 0:
        if x:
            ans += 1
        return
    if x == 0:
        return
    if x > total[n - 1] + 2:
        ans += p[n - 1] + 1
        search(x - (2 + total[n - 1]), n - 1)
    elif x == total[n - 1] + 2:
        ans += p[n - 1] + 1
    else:
        search(x - 1, n - 1)


search(X, N)
print(ans)

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


def search(x, n):
    global ans
    if n == 0:
        if x:
            ans += 1
        return
    if x == 0:
        return
    a = q[n - 1] + 2
    b = p[n - 1] + 1
    if x > a:
        ans += b
        search(x - a, n - 1)
    elif x == a:
        ans += b
    else:
        search(x - 1, n - 1)


search(X, N)
print(ans)

-from functools import lru_cache - - -@lru_cache() -def f(n): -    if n == 0: -        return 1 -    return 2 * f(n - 1) + 1 - - -@lru_cache() -def g(n): -    if n == 0: -        return 1 -    return 2 * g(n - 1) + 3 - - -total = [g(i) for i in range(N + 1)] -p = [f(i) for i in range(N + 1)] +q = [1] * (N + 1) +p = [1] * (N + 1) +for i in range(1, N + 1): +    q[i] = 2 * q[i - 1] + 3 +    p[i] = 2 * p[i - 1] + 1 -    if x > total[n - 1] + 2: -        ans += p[n - 1] + 1 -        search(x - (2 + total[n - 1]), n - 1) -    elif x == total[n - 1] + 2: -        ans += p[n - 1] + 1 +    a = q[n - 1] + 2 +    b = p[n - 1] + 1 +    if x > a: +        ans += b +        search(x - a, n - 1) +    elif x == a: +        ans += b