import Control.Monad   (replicateM)
import Data.List       (sort)
import Data.List.Split (splitOn)
main = do
    w <- readLn
    n <- readLn
    bs <- replicateM n getLine
    let lines = [1..w]
        bars  = map (makePair.map read.splitOn ",") bs :: [(Int,Int)]
    mapM_ print $ map snd.sort.map (pursueBars bars) $ lines

makePair [a,b] = (a,b)

pursueBars bars i = (finali, i)
    where
        finali = pursue bars i

pursue []     i = i
pursue (b:bs) i = pursue bs (swap b i)

swap (left,right) i
    | left  == i = right
    | right == i = left
    | otherwise  = i