local n,x=io.read("n","n")
local b,p={[0]=1},{[0]=1}
for i=1,n do
    b[i]=b[i-1]*2+3
    p[i]=p[i-1]*2+1
end

local function patty(n,x)
    if n==0 then
        return (x>0 and 1 or 0)
    elseif x<=b[n-1]+1 then
        return patty(n-1,x-1)
    else
        return p[n-1]+1+patty(n-1,x-2-b[n-1])
    end
end

print(string.format("%d",patty(n,x)))