
import Data.Array (Array, listArray, (!))

b = listArray (0,50) $ iterate (\x->2*x+3) 1
p = listArray (0,50) $ iterate (\x->2*x+1) 1

f n 1 = 0
f n x
  | x<=1+(b!(n-1))   = f (n-1) (x-1)
  | x==2+(b!(n-1))   = (p!(n-1)) + 1
  | x<=2+2*(b!(n-1)) = (p!(n-1)) + f (n-1) (x-2-(b!(n-1))) + 1
  | x==3+2*(b!(n-1)) = 2*(p!(n-1)) + 1

main = do
  [n,x] <- map read . words <$> getLine
  print $ f n x
