import Data.Int

main = do
    [n,x] <- map read . words <$> getLine :: IO [Int] 
    print $ eat x $ mkBurgerNum n

-- (total，pate)
mkBurgerNum :: Int -> [[Int]]
mkBurgerNum n 
    | n == 0 = [[1,1]]
    | otherwise = [2*m+3, 2*l+1]:x
    where 
        x = mkBurgerNum (n-1)
        m = x !! 0 !! 0
        l = x !! 0 !! 1

-- x mkBurgerNum 
eat :: Int -> [[Int]] -> Int 
eat x (berger:[]) = 1
eat x (berger:child_berger:xs)
    | x == 1 = 0
    | x > child_berger_num + 2 = child_pate_num + 1 + eat (x - 2 - child_berger_num) (child_berger:xs)
    | x == child_berger_num + 2 = 1 + child_pate_num
    | otherwise = eat (x-1) $ child_berger:xs
    where 
        child_berger_num = child_berger !! 0 
        child_pate_num = child_berger !! 1