
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Map as M

solve :: M.Map Int Int -> [[Int]] -> M.Map Int Int
solve m [] = m
solve m (s:sc)
    | x == 1 && y == 0 = M.empty
    | m' == Nothing = solve (M.insert x y m) sc
    | (fromJust m') == y = solve m sc
    | otherwise = M.empty
        where
            x = s!!0
            y = s!!1
            m' = M.lookup x m

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    sc <- replicateM m (map read . words <$> getLine) :: IO [[Int]]
    let m' = solve M.empty sc
    if m' == M.empty
        then print $ -1
        else do
            let m'' = M.foldlWithKey (\acc k v -> acc + (10^(n-k)*v)) 0 m'
            if m'' < 100
                then print $ m'' + 100
                else print $ m''
