import Data.Char
import Control.Monad

parseInputLine :: String -> String -> [Int]
parseInputLine val [] = [read val]
parseInputLine val (' ':xs) = [read val] ++ parseInputLine "" xs
parseInputLine val (x:xs) = parseInputLine (val ++ [x]) xs

solve :: String -> [[Int]] -> Int
solve str []
  | all (== '0') str = -1
  | c == '0' = read ('1':drop 1 str)
  | otherwise = read str
  where c = head str
solve str (sc:scs) = if r `elem` ['0', chr (ord '0' + c)]
                        then solve new_str scs
                        else -1
  where s = sc!!0 - 1
        c = sc!!1
        r = str!!s
        new_str = (take s str) ++ (show c) ++ (drop (s+1) str)

main :: IO ()
main = do
  inNM <- getLine
  let nm = parseInputLine "" inNM
      n = nm!!0
      m = nm!!1
  inScs <- replicateM m getLine
  let scs = map (parseInputLine "") inScs
      initStr = take n (repeat '0')
      output = solve initStr scs

  putStrLn (show output)
