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

solve 0 0 = 0
solve 0 _ = 1
solve n x | x == 1 = 0
          | x <= 1 + a = solve (n-1) (x-1)
          | x == 2 + a = b + 1
          | x <= 2 + 2 * a = b + 1 + solve (n-1) (x-2-a)
          | x == 3 + 2 * a = 2*b+1
     where f 0 = 1
           f l = 2 * f (l-1) + 3
           p 0 = 1
           p l = 2 * p (l-1) + 1
           a = f (n-1)
           b = p (n-1)