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]]
    if m == 0
        then print $ (10^(n-1))
        else do
            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'' < (10^(n-1))
                        then print $ m'' + (10^(n-1))
                        else print $ m''
