from functools import lru_cache



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

sizes = [1]

for i in range(50):

    sizes.append(sizes[-1] * 2 + 3)





@lru_cache(maxsize=None)

def count_patti(level, index):

    """

    左から index 番目までのパティの数

    :param level:

    :param index:

    :return:

    """

    if level == 0:

        return 1

    if index == 0:

        return 0

    if 1 <= index < (sizes[level] - 1) / 2:

        return count_patti(level - 1, index - 1)

    if index == (sizes[level] - 1) / 2:

        return count_patti(level - 1, sizes[level - 1] - 1) + 1

    if (sizes[level] - 1) / 2 < index < sizes[level] - 1:

        return count_patti(level - 1, sizes[level - 1] - 1) + 1 + \

               count_patti(level - 1, index - (sizes[level] - 1) / 2 - 1)

    else:

        return count_patti(level - 1, sizes[level - 1] - 1) + 1 + \

               count_patti(level - 1, sizes[level - 1] - 1)





print(count_patti(n, x - 1))

import os

import sys



if os.getenv("LOCAL"):

    sys.stdin = open("_in.txt", "r")



sys.setrecursionlimit(10 ** 9)

INF = float("inf")

IINF = 10 ** 18

MOD = 10 ** 9 + 7

# MOD = 998244353



N, X = list(map(int, sys.stdin.buffer.readline().split()))



sizes = [1]

for _ in range(N):

    sizes.append(sizes[-1] * 2 + 3)

patties = [1]

for _ in range(N):

    patties.append(patties[-1] * 2 + 1)





def solve(n, x):

    if sizes[n] <= x:

        return patties[n]

    if x <= 0:

        return 0

    ret = 0

    ret += solve(n - 1, x - 1)

    ret += 1 if x > sizes[n] // 2 else 0

    ret += solve(n - 1, x - sizes[n] // 2 - 1)

    return ret





ans = solve(N, X)

print(ans)

from functools import lru_cache

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


@lru_cache(maxsize=None)
def count_patti(level, index):
    """
    左から index 番目までのパティの数
    :param level:
    :param index:
    :return:
    """
    if level == 0:
        return 1
    if index == 0:
        return 0
    if 1 <= index < (sizes[level] - 1) / 2:
        return count_patti(level - 1, index - 1)
    if index == (sizes[level] - 1) / 2:
        return count_patti(level - 1, sizes[level - 1] - 1) + 1
    if (sizes[level] - 1) / 2 < index < sizes[level] - 1:
        return (
            count_patti(level - 1, sizes[level - 1] - 1)
            + 1
            + count_patti(level - 1, index - (sizes[level] - 1) / 2 - 1)
        )
    else:
        return (
            count_patti(level - 1, sizes[level - 1] - 1)
            + 1
            + count_patti(level - 1, sizes[level - 1] - 1)
        )


print(count_patti(n, x - 1))

import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N, X = list(map(int, sys.stdin.buffer.readline().split()))
sizes = [1]
for _ in range(N):
    sizes.append(sizes[-1] * 2 + 3)
patties = [1]
for _ in range(N):
    patties.append(patties[-1] * 2 + 1)


def solve(n, x):
    if sizes[n] <= x:
        return patties[n]
    if x <= 0:
        return 0
    ret = 0
    ret += solve(n - 1, x - 1)
    ret += 1 if x > sizes[n] // 2 else 0
    ret += solve(n - 1, x - sizes[n] // 2 - 1)
    return ret


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

-from functools import lru_cache +import os +import sys -n, x = map(int, input().split()) +if os.getenv("LOCAL"): +    sys.stdin = open("_in.txt", "r") +sys.setrecursionlimit(10**9) +INF = float("inf") +IINF = 10**18 +MOD = 10**9 + 7 +# MOD = 998244353 +N, X = list(map(int, sys.stdin.buffer.readline().split())) -for i in range(50): +for _ in range(N): +patties = [1] +for _ in range(N): +    patties.append(patties[-1] * 2 + 1) -@lru_cache(maxsize=None) -def count_patti(level, index): -    """ -    左から index 番目までのパティの数 -    :param level: -    :param index: -    :return: -    """ -    if level == 0: -        return 1 -    if index == 0: +def solve(n, x): +    if sizes[n] <= x: +        return patties[n] +    if x <= 0: -    if 1 <= index < (sizes[level] - 1) / 2: -        return count_patti(level - 1, index - 1) -    if index == (sizes[level] - 1) / 2: -        return count_patti(level - 1, sizes[level - 1] - 1) + 1 -    if (sizes[level] - 1) / 2 < index < sizes[level] - 1: -        return ( -            count_patti(level - 1, sizes[level - 1] - 1) -            + 1 -            + count_patti(level - 1, index - (sizes[level] - 1) / 2 - 1) -        ) -    else: -        return ( -            count_patti(level - 1, sizes[level - 1] - 1) -            + 1 -            + count_patti(level - 1, sizes[level - 1] - 1) -        ) +    ret = 0 +    ret += solve(n - 1, x - 1) +    ret += 1 if x > sizes[n] // 2 else 0 +    ret += solve(n - 1, x - sizes[n] // 2 - 1) +    return ret -print(count_patti(n, x - 1)) +ans = solve(N, X) +print(ans)