N, X = [int(_) for _ in input().split()]





def calc(n, x, cache = {}):

    #print("calc", n, x)

    key = (n, x)

    if key in cache:

        return cache[key]

    if n == 1:

        if x < 2:

            result = 0

        elif x < 5:

            result = x - 1

        else:

            result = 3

    else:

        plen = 2 * 2 ** n - 3

        if x == 1:

            result = 0

        elif x < 2 + plen:

            result = calc(n - 1, x - 1)

        elif x == 2 + plen:

            result = calc(n - 1, x - 1) + 1

        else:

            result = calc(n - 1, plen) + 1 + calc(n - 1, x - 2 - plen)

    #print("calc", n, x, "=", result)

    cache[key] = result

    return result



result = calc(N, X)



print(result)

N, X = [int(_) for _ in input().split()]



def calc(n, x, cache = {}):

    if n == 1:

        return min(max(x - 1, 0), 3)

    else:

        plen = 2 * 2 ** n - 3

        if x == 1:

            return 0

        elif x >= 4 * 2 ** n - 3:

            return 2 * 2 ** n - 1

        elif x < 2 + plen:

            return calc(n - 1, x - 1)

        elif x == 2 + plen:

            return calc(n - 1, x - 1) + 1

        else:

            return 2 ** n + calc(n - 1, x - 2 - plen)



result = calc(N, X)



print(result)

N, X = [int(_) for _ in input().split()]


def calc(n, x, cache={}):
    # print("calc", n, x)
    key = (n, x)
    if key in cache:
        return cache[key]
    if n == 1:
        if x < 2:
            result = 0
        elif x < 5:
            result = x - 1
        else:
            result = 3
    else:
        plen = 2 * 2**n - 3
        if x == 1:
            result = 0
        elif x < 2 + plen:
            result = calc(n - 1, x - 1)
        elif x == 2 + plen:
            result = calc(n - 1, x - 1) + 1
        else:
            result = calc(n - 1, plen) + 1 + calc(n - 1, x - 2 - plen)
    # print("calc", n, x, "=", result)
    cache[key] = result
    return result


result = calc(N, X)
print(result)

N, X = [int(_) for _ in input().split()]


def calc(n, x, cache={}):
    if n == 1:
        return min(max(x - 1, 0), 3)
    else:
        plen = 2 * 2**n - 3
        if x == 1:
            return 0
        elif x >= 4 * 2**n - 3:
            return 2 * 2**n - 1
        elif x < 2 + plen:
            return calc(n - 1, x - 1)
        elif x == 2 + plen:
            return calc(n - 1, x - 1) + 1
        else:
            return 2**n + calc(n - 1, x - 2 - plen)


result = calc(N, X)
print(result)

-    # print("calc", n, x) -    key = (n, x) -    if key in cache: -        return cache[key] -        if x < 2: -            result = 0 -        elif x < 5: -            result = x - 1 -        else: -            result = 3 +        return min(max(x - 1, 0), 3) -            result = 0 +            return 0 +        elif x >= 4 * 2**n - 3: +            return 2 * 2**n - 1 -            result = calc(n - 1, x - 1) +            return calc(n - 1, x - 1) -            result = calc(n - 1, x - 1) + 1 +            return calc(n - 1, x - 1) + 1 -            result = calc(n - 1, plen) + 1 + calc(n - 1, x - 2 - plen) -    # print("calc", n, x, "=", result) -    cache[key] = result -    return result +            return 2**n + calc(n - 1, x - 2 - plen)