main=do
 [n,m]<-map read.words<$>getLine
 sc<-map(map read.words).lines<$>getContents
 let ok=filter(\x->f(show x)sc)[10^(n-1)-1..10^n-1]
 print$if null ok then -1 else head ok
f x[]=True
f x([s,c]:sc)=if fromEnum(x!!(s-1))-48==c then f x sc else False
