import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
listToTuple (x : y : _) = (x, y)

main = do
    [n, m] <- getIntList
    scs <- sort . map listToTuple <$> replicateM m getIntList
    let ans = solve n 1 10 scs
    if ans < 0 then print (-1) else print ans

solve n 1 t ((s, c) : scs) | s /= 1 && t == 10 = (f n) + solve n 2 10 ((s, c) : scs)
                           | s /= 1 = solve n 2 10 ((s,c) : scs)
                           | s == 1 && c /= 0 && t == 10 = c * 10 ^ (n-1) + solve n 1 c scs
                           | s == 1 && c /= 0 && c == t = solve n 1 c scs
                           | otherwise = - 10 ^ n
solve n m t ((s, c) : scs) | s /= m = solve n (m+1) 10 ((s, c) : scs)
                           | s == m && t == 10 = c * 10^(n - s) + solve n m c scs
                           | s == m && c == t = solve n m c scs
                           | otherwise = - 10 ^ n
solve _ _ _ _ = 0

f n | n == 1 = 0
    | otherwise = 10 ^(n-1)