import           Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  let n' = 2 ^ n
  as <- replicateM n' readLn :: IO [Int]
  print $ solve as

solve as
  | length as == 1 = head as
  | otherwise = solve (go as)
  where
    go [] = []
    go (x:y:zs)
      | x == y = x:go zs
      | otherwise = abs (x - y) : go zs
