import Control.Applicative main = do [n]:_:l <- map words . lines <$> getContents putStrLn $ foldl f n l where f a [b,c] | a==b = c | a==c = b | otherwise = a