main = getContents >>= putStrLn . fout . drawing_lots . fin . lines
fin (w:n:xs) = (read w, map readpair xs)
 where readpair = map read . splitOn ','
fout = unlines . map show

splitOn c str = [xs,ys]
 where (xs,(y:ys)) = break (== c) str

drawing_lots (w,rs) = map (amida (reverse rs)) [1..w]
 where
  amida [] n = n
  amida ([a,b]:xs) n = amida xs (if a==n then b else (if b==n then a else n))