import Data.Array.Unboxed
import Data.List

main = interact $ show . sol . get

get = fmap (fmap read . words) . lines

sol ([n,m]:scs) = if ss==nub ss && 10^(n-1)<=x then x else (-1)
  where
  ns = nub $ sort scs
  ps = (\[s,c] -> (s,c)) <$> ns
  ss = fst <$> ps
  ar = accumArray (+) 0 (1,n) ps :: UArray Int Int
  x = foldl1 (\s c -> 10*s+c) $ elems ar
