import Control.Monad
main=do
 [n,m]<-map read.words<$>getLine
 i<-replicateM m$(\[s,c]->(\a->a!!((read s)-1)==(c!!0))).words<$>getLine
 let j=filter(\a->all(id)$map(\f->f a)i)[b|b<-map show[0..1000],length b==n]
 putStrLn$if null j then"-1"else j!!0