import Control.Monad

makeList n
   |n==1      = [0..9]
   |otherwise = [10^(n-1)..10^n-1]

main = do
   [n,m] <- map read . words <$> getLine
   sc <- replicateM m $ map read . words <$> getLine
   let ans = filter (\x -> if and (map (\y -> x !! (((sc !! y) !! 0)-1) == (toEnum $ 48 + ((sc !! y) !! 1))) [0..m-1]) then True else False) $ map show $ makeList n
   if ans == []
      then putStrLn $ show $ -1
      else putStrLn $ head ans