from functools import lru_cache



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



@lru_cache(maxsize=None)

def length(level):

    if level <= 0:

        return 1

    return length(level - 1) * 2 + 3



@lru_cache(maxsize=None)

def search(level, right):

    if level == 0:

        return 1



    ret = 0

    right -= 1

    if length(level - 1) <= right:

        ret += search(level - 1, length(level - 1))

        right -= length(level - 1)



        if right > 0:

            ret += 1

        right -= 1



    if 0 < right:

        ret += search(level - 1, right)

    return ret



print((search(N, X)))

from functools import lru_cache



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



@lru_cache(maxsize=None)

def size(level):

    return 1 if level == 0 else size(level - 1) * 2 + 3



@lru_cache(maxsize=None)

def calc(level, N):

    if level == 0:

        return 1 if N > 0 else 0



    N = min(N, size(level))



    ret = 0

    N -= 1



    if N >= size(level - 1):

        ret += calc(level - 1, size(level - 1))

        N -= size(level - 1)



        if N >= 1:

            ret += 1

            N -= 1



    return ret + calc(level - 1, N)



print((calc(N, X)))

from functools import lru_cache

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


@lru_cache(maxsize=None)
def length(level):
    if level <= 0:
        return 1
    return length(level - 1) * 2 + 3


@lru_cache(maxsize=None)
def search(level, right):
    if level == 0:
        return 1
    ret = 0
    right -= 1
    if length(level - 1) <= right:
        ret += search(level - 1, length(level - 1))
        right -= length(level - 1)
        if right > 0:
            ret += 1
        right -= 1
    if 0 < right:
        ret += search(level - 1, right)
    return ret


print((search(N, X)))

from functools import lru_cache

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


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


@lru_cache(maxsize=None)
def calc(level, N):
    if level == 0:
        return 1 if N > 0 else 0
    N = min(N, size(level))
    ret = 0
    N -= 1
    if N >= size(level - 1):
        ret += calc(level - 1, size(level - 1))
        N -= size(level - 1)
        if N >= 1:
            ret += 1
            N -= 1
    return ret + calc(level - 1, N)


print((calc(N, X)))

-def length(level): -    if level <= 0: -        return 1 -    return length(level - 1) * 2 + 3 +def size(level): +    return 1 if level == 0 else size(level - 1) * 2 + 3 -def search(level, right): +def calc(level, N): -        return 1 +        return 1 if N > 0 else 0 +    N = min(N, size(level)) -    right -= 1 -    if length(level - 1) <= right: -        ret += search(level - 1, length(level - 1)) -        right -= length(level - 1) -        if right > 0: +    N -= 1 +    if N >= size(level - 1): +        ret += calc(level - 1, size(level - 1)) +        N -= size(level - 1) +        if N >= 1: -        right -= 1 -    if 0 < right: -        ret += search(level - 1, right) -    return ret +            N -= 1 +    return ret + calc(level - 1, N) -print((search(N, X))) +print((calc(N, X)))