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=(+(10^(n-1)))$length$takeWhile(\a->not$all(id)$map(\f->f a)i)[b|b<-map show[0..1000],length b==n]
 print$if j==(10^n)then(-1)else j