import qualified Data.Text as T import qualified Data.Text.IO as TI import Control.Applicative readLines = sequence.flip replicate TI.getLine readInt::String->Int readInt=read change locate []=locate change locate ((a:b:_):xs) = if locate == a then change b xs else if locate == b then change a xs else change locate xs main = do n <- readInt<$>getLine m <- readInt<$>getLine list <- fmap (fmap (readInt.T.unpack).T.split(==' '))<$>readLines m putStrLn$show$change n list