n,m=map(int,input().split())
s,c=[],[]
t=0
for i in range(m):
    a,b=map(int,input().split())
    s.append(a)
    c.append(b)
ans=[10]*n
for i in range(m):
    if ans[s[i]-1]==10:
        ans[s[i]-1]=c[i]
    elif ans[s[i]-1]!=10 and ans[s[i]-1]!=c[i]:
        t=-1
if t==-1:
    print(-1)
elif  n==1 and (ans[0]==0 or ans[0]==10):
    print(0)
elif ans[0]==0:
    print(-1)
else:
    for i in range(n):
        if i==0 and ans[0]==10:
            ans[0]==1
        elif ans[i]==10:
            ans[i]=0
    print(*ans,sep='')