
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord
import Data.Maybe


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [n,m] <- r' :: IO [Int]
    sc <- nub <$> replicateM m (r' >>= (\[s,c] -> return (s,c)))
    let r = tr $ sl (replicate n Nothing) sc
    print $ if length (show r) == n
        then r
        else if r /= -1 && lookup 0 sc /= Just 0 then r + 10^(n-1) else r

sl :: [Maybe Int] -> [(Int,Int)] -> Maybe [Int]
sl xs [] = Just $ map (fromMaybe 0) xs
sl xs ((s,c):sc) = case xs!!(s-1) of
    Nothing -> sl (take (s-1) xs ++ Just c:drop s xs) sc
    Just _  -> Nothing
tr :: Maybe [Int] -> Int
tr Nothing = -1
tr (Just xs) = sum $ zipWith (*) [10^x | x<-[0..]] (reverse xs)

