main = getLine >>= solve . read where solve n = getLine >> getContents >>= print . solve' n . map (map read . words) . lines solve' :: Int -> [[Int]] -> Int solve' n = foldl (\acc [p, q] -> if p == acc then q else if q == acc then p else acc) n