program atcoder
    implicit none
    integer(8) :: a(0:51),b(0:51),i,ans,n,x
    read*,n,x
    ans = 0
    a(0) = 1
    b(0) = 1
    do i=1,50
        a(i) = a(i-1) * 2 + 3
        b(i) = b(i-1) * 2 + 1 
    enddo
    call dfs(n,x)
    write(*,'(I0)')ans
!----------------------functions--------------------------
contains

recursive subroutine dfs(nn,xx)
    implicit none
    integer(8) :: nn,xx
    if(nn==0 .and. xx>=1)then
        ans = ans + 1
    else if(xx<=1)then
        ans = ans
    else if(xx>a(nn)/2)then
        ans = ans+1+b(nn-1)
        call dfs(n-1,xx-a(nn)/2-1)
    else if(xx==a(nn)/2)then
        ans = ans + b(n-1)
    else
        call dfs(nn-1,xx-1)
    end if
    return
end subroutine dfs

end program atcoder