import Control.Monad main = do n <- readLn m <- readLn ws <- replicateM m $ map read . words <$> getLine :: IO [[Int]] -- putStrLn . show $ n + 0 -- putStrLn . show $ m + 0 -- print ws putStrLn . show $ solve n ws solve a ([x,y]:ws) | ws == [] = check a x y | otherwise = solve (check a x y) ws check a x y | a == x = y | a == y = x | otherwise = a