import Control.Monad

readWords = map read . words <$> getLine

solve :: [Int] -> [(Int -> Bool)] -> [Int]
solve inData conditions
 | null conditions  = inData
 | otherwise        = solve newInData (tail conditions)
   where newInData = filter (head conditions) inData

main = do
 [n,m]    <- readWords :: IO [Int]
 inputStr <- replicateM m readWords
 let conditions = map (\[s,c] x -> (x `div` (10^(n-s))) `mod` 10 == c) inputStr
 print $ (\x -> if null x then -1 else minimum x) $ if n == 1 then [0..9] else solve [10^(n-1)..((10^n) - 1)] conditions
