import qualified Data.ByteString.Char8 as B
import Data.Char
import Control.Monad
readInput :: Read a => IO [a]
readInput = map read . words <$> getLine

main = do
    [n, m] <- readInput
    constraints <- replicateM m readInput
    case [ i | i <- [0..999]
        , let str = B.pack $ show (i :: Int)
        , B.length str == n
        , all (\[s, c] -> str `B.index` pred s == intToDigit c) constraints
        ] of
            [] -> print (-1)
            i : _ -> print i