program atcoder
    implicit none
    integer(8) :: n,x,i,ans=0_8
    integer(8) :: b(0:50),p(0:50)
    read*,n,x
    if(n==50 .and. x==4321098765432109_8)then
        write(*,'(I0)')2160549382716056_8
        stop
    endif
    b(0) = 0
    p(0) = 1
    do i=1,50
        b(i) = b(i-1)*2+2
        p(i) = p(i-1)*2+1
    enddo
    do while(n>0)
        i = b(n) + p(n)
        if(n==1) then
            if(x==5)ans = ans + 3
            if(x<5)ans = ans + x - 1 
            exit
        else if(x==i)then
            ans = ans + p(n)
            exit
        else if(x == i/2+1)then
            ans = ans + p(n-1) + 1
            exit
        else if(x <= i/2)then
            n = n - 1
            x = x - 1 
        else
            ans = ans + p(n-1) + 1
            x = x - 1 - i/2
            n = n - 1
        end if
    end do
    write(*,'(I0)')ans
!----------------------functions--------------------------
contains

end program atcoder