import Control.Monad
import Data.Maybe
import Data.List
import Data.Char

main = do
  [n, m] <- map read.words <$> getLine
  sc <- replicateM m $ readPair.words <$> getLine
  print $ solve n sc

solve :: Int -> [(Int, Int)] -> Int
solve n sc = fromMaybe (-1) $ find eval can where
  eval n = all (\(s, c) -> show n !! (s-1) == intToDigit c) sc
  can = case n of 
    1 -> [0..9]
    2 -> [10..99]
    3 -> [100..999]

readPair [a, b] = (read a, read b)