local function memoize(f)
    local cache = {}
    local function key(...)
        local args = {...}
        local k = tostring(args[1])
        for i=2,#args do
            k = k .. "*" .. tostring(args[i])
        end
        return k
    end
    return function(...)
        local k = key(...)
        if cache[k] then
            return cache[k]
        end
        local r = f(...)
        cache[k] = r
        return r
    end
end

local thickness
thickness = memoize(function(n)
    if n == 0 then
        return 1
    else
        return 2 * thickness(n-1) + 3
    end
end)

local patties
patties = memoize(function (n, x)
    if n == 0 then
        return 1
    end
    local th_upper = thickness(n-1)
    if x == 1 then
        return 0
    elseif x <= th_upper + 1 then
        return patties(n-1, x-1)
    elseif x == th_upper + 2 then
        return 1 + patties(n-1, th_upper)
    else
        return 1 + patties(n-1, th_upper) + patties(n-1, x-2-th_upper)
    end
end)

local N, X = io.read("n", "n")
print(patties(N,X))
