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

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map read . words <$> getLine :: IO [Int]
cond t f c = if c then t else f
-- end of templete

swap s p = lp ++ rv : mp ++ lv : rp
  where
    lp = take (i-1) s
    lv = s !! (i-1)
    mp = drop i . take (j-1) $ s
    rv = s !! (j-1)
    rp = drop (j) s
    i = minimum p
    j = maximum p

main = do
    w <- getInt
    n <- getInt
    bs <- map (map readInt . wordsBy (==',')) <$> replicateM n getLine
    mapM_ print $ foldl swap [1..w] bs