{-# LANGUAGE OverloadedStrings #-}

import Data.List
import Control.Applicative
import qualified Data.Text as T
import qualified Data.Text.IO as T

textToInt :: T.Text -> Int
textToInt t = (read . T.unpack) t :: Int

passHorizontalLine :: (Int, Int) -> Int -> Int
passHorizontalLine (p1, p2) n
    | p1 == n   = p2
    | p2 == n   = p1
    | otherwise = n

passHorizontalLines :: [(Int, Int)] -> Int -> Int
passHorizontalLines [] n = n
passHorizontalLines (p:ps) n = passHorizontalLines ps $ passHorizontalLine p n

passAmidakuji :: [(Int, Int)] -> [Int] -> [Int]
passAmidakuji hs ps = map snd $ sort $ zip [passHorizontalLines hs p | p <- ps] ps

main :: IO ()
main = do
    ps <- (\w -> [1 .. w]) . textToInt <$> T.getLine
    _ <- T.getLine
    hs <- map (\[a, b] -> (a, b)) . map (map textToInt) . map (T.splitOn ",") . T.lines <$> T.getContents
    putStr . unlines . map show $ passAmidakuji hs ps