import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

main = do
  n <- BS.getLine
  q <- readLn
  a <- map BS.words <$> replicateM q BS.getLine
  
  putStrLn $ BS.unpack $ f n a
  
f :: BS.ByteString -> [[BS.ByteString]] -> BS.ByteString
f as [] = as
f as (co:[])
  | length co == 1 = BS.reverse as 
  | otherwise = f2 as co 
f as (x:xs)
  | length x == 1 = f (BS.reverse as) xs
  | otherwise = f (f2 as x) xs

f2 :: BS.ByteString -> [BS.ByteString] -> BS.ByteString
f2 s [_, a, b]
  | BS.elem '1' a = BS.append b  s
  | otherwise = BS.append s  b
  