{-# LANGUAGE OverloadedStrings #-}
import Data.Char
import Data.List
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [n,m] <- parseLine <$> BS.getLine
  xs <- replicateM m (toTuple.parseLine <$> BS.getLine)
  BS.putStrLn . BS.pack . show $ fromMaybe (-1) (solve n xs) 
  where
     parseLine = unfoldr (BS.readInt . BS.dropWhile isSpace)

toTuple :: [Int] -> (Int, Int)
toTuple (x:y:_) = (x, y)

solve :: Int -> [(Int,Int)] -> Maybe Int
solve n xs = conds >>= generate n
  where
    conds = foldM (process n) [] xs

process :: Int -> [(Int,Int)] -> (Int,Int) -> Maybe [(Int, Int)]
process n acc (s, c) = case lookup s acc of
  Just c' -> if c /= c'
    then Nothing
    else Just acc
  Nothing -> if and [(n/=1), (s==1), (c==0)]
    then Nothing
    else Just ((s,c):acc)

generate :: Int -> [(Int,Int)] -> Maybe Int
generate _ [] = Nothing
generate n xs = Just . read . concat . map (show . genDigit) $ [1..n]
  where
    genDigit d = if (n/=1) && (d==1)
      then fromMaybe 1 (lookup 1 xs)
      else fromMaybe 0 (lookup d xs)