import Control.Monad
import Control.Applicative
import Data.List.Split

solve :: [[Int]] -> Int -> Int
solve [] n     = n
solve ([a,b]:xs) n
	| n == a = solve xs b
	| n == b = solve xs a
	| otherwise = solve xs n

main = do
	w <- readLn :: IO Int
	n <- readLn
	lines <- replicateM n (map (read :: String -> Int) . splitOn "," <$> getLine)
	
	mapM_ print $ map (solve (reverse lines)) [1..w]