n,m=map(int,input().split())
cnt=[-1]*n
ans=0
for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0:
        ans=-1
        break
    elif cnt[s-1]==-1:
        cnt[s-1]=c
    elif c!=cnt[s-1]:
        ans=-1
        break
if ans==-1:
    print(ans)
else:
    for i in range(n):
        if i==0 and cnt[0]==-1:
            cnt[0]=1
        elif cnt[i]==-1:
            cnt[i]=0
        ans+=cnt[i]*10**(n-i-1)
    print(ans)