program prob6
    implicit none
    integer(16)::n, x, d(0:50), p(0:50), b(0:50), tmp, ans
    integer::i, j
    read(*,*) n, x

    tmp = 1
    d(0) = 1
    p(0) = 1
    b(0) = 0
    do i = 1, 50
        d(i) = d(i-1)*2 + 3
        p(i) = p(i-1)*2 + 1
        b(i) = b(i-1)*2 + 2
    end do
    if(x == d(n)) then
        write(*,*) p(n)
        stop
    end if
    ans = 0
    tmp = x
    do i = n-1, 0, -1
        tmp = tmp - 1
        !write(*,*) tmp
        if(tmp >= d(i)) then
            ans = ans + p(i)
            tmp = tmp - d(i)
            if(tmp > d(i)) then
                ans = ans + p(i) + 1
                tmp = tmp - d(i) - 1
            else if(tmp > 0) then
                ans = ans + 1
                tmp = tmp - 1 
            end if
        end if
        !write(*,*) ans
    end do
    write(*,*) ans
    stop
end program