import Control.Applicative
import Control.Monad
import Data.List

burgersize :: Integer -> Integer
burgersize lv 
  | lv==0 = 1
  | lv>0  = 3 + 2 * burgersize (lv - 1)

pate 0 = 1
pate lv = 1 + 2 * pate (lv-1)

burger :: Integer -> Integer -> Integer
burger 0 0 = 0
burger 0 _ = 1
burger lv x
  | x == 0 = 0
  | x >= thissize = pate lv
  | x <= 1 + lowersize = burger (lv-1) (max 0 (x - 1))
  | otherwise = pate (lv-1) + 1 + burger (lv-1) (max 0 (x - 2 - lowersize))
  where
    thissize = burgersize lv
    lowersize = burgersize (lv-1)
    
solve [n, x] = print $ burger n x

main = map read . words <$> getLine >>= solve