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 ns = f n
    print $ head [n | n <- ns, and $ map (\(s, c) -> (show n) !! (s - 1) == head (show c)) scs]

f n | n == 1 = [0..9]
    | n == 2 = [10..99]
    | n == 3 = [100..999]