n,m =map(int,input().split())
s=[0]*m
c=[0]*m
for _ in range(m):
    s[_],c[_]=map(int,input().split())
ans=["a"]*n
xa=0

for i in range(m):
    if s[i]-1<=0:
        print(-1)
        xa=1        
        break
    if isinstance(ans[s[i]-1],int)==True and ans[s[i]-1]!=c[i]:
        print(-1)
        xa=1
        break
    if ans[s[i]-1]=="a":
        ans[s[i]-1]=c[i]

if ans[0]==0:
    if xa!=1:
        print(-1)
        xa=1

for i in range(n):
    if ans[i]=="a":
        if i==0:
            ans[i]=1
        if i!=0:
            ans[i]=0

if xa!=1:
    an=print(*ans,sep="")