program christmas
  implicit none
  integer :: n, i
  integer(8) :: x, p(0:50) = 0_8, m(0:50) = 0_8
  p(0) = 1_8
  m(0) = 1_8
  read(*,*) n, x
  do i = 1, n
    p(i) = 2_8*p(i-1)+1_8
    m(i) = 2_8*m(i-1)+3_8
  end do
  write(*,'(i0)') eat(n,x)
contains
  recursive function eat(n,x) result(ret)
    integer, intent(in) :: n
    integer(8), intent(in) :: x
    integer(8) :: ret
    if (x == 1) then
      ret = 0_8
    else if (x == m(n)) then
      ret = p(n)
    else if (x == m(n-1)+1_8 .or. x == m(n-1)+2_8) then
      ret = p(n-1)+x-m(n-1)-1_8
    else if (x <= m(n-1)) then
      ret = eat(n-1,x-1_8)
    else
      ret = p(n-1)+1_8+eat(n-1,x-m(n-1)-2_8)
    end if
  end
end program christmas