module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import qualified Data.Set  as S
import qualified Data.IntMap.Strict as IM


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [(Int, Int)] -> Int
solve n m = 
    let
        go :: (Int, Int) -> (Maybe (IM.IntMap Int)) -> (Maybe (IM.IntMap Int))
        go (keta, num) Nothing = Nothing
        go (1, 0) (Just dic) = if n == 1 then Just $ IM.insert 1 0 dic else Nothing
        go (keta, num) (Just dic)
            | keta > n = Nothing
            | IM.lookup keta dic == Nothing = Just $ IM.insert keta num dic
            | IM.lookup keta dic == Just num = Just dic
            | otherwise = Nothing
        dict = foldr go (Just IM.empty) m
    in
    case dict of
        Nothing -> -1
        Just d ->
            foldl' (\s  keta -> s * 10 + (IM.findWithDefault 1 keta d) )   0 [1..n]


main = do
    (n, m) <- readTuple2
    conds <- replicateM m readTuple2
    print $ solve n conds
