{-# LANGUAGE BangPatterns #-}


import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import System.IO
import Control.Monad.State.Strict

patties :: Int -> Int
patties level = bit (level+1) - 1

layers :: Int -> Int
layers level = bit (level+2) - 3

bread :: State Int Int
bread = do
  layers <- get
  if layers > 0 then do
    put $ layers - 1
    return 0
  else
    return 0

eat :: Int -> State Int Int
eat 0 = do
  layers <- get
  if layers > 0 then do
    put $ layers - 1
    return 1
  else
    return 0
eat lv = do
  layersToEat <- get
  if layersToEat >= layers lv then do
    put $ layersToEat - layers lv
    return $ patties lv
  else if layersToEat > 0 then do
    bread
    first <- eat (lv - 1)
    second <- eat 0
    third <- eat (lv - 1)
    bread
    return $ first + second + third
  else
    return 0

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