n,m=map(int,input().split())
ans=[-1 for i in range(n)]
for i in range(m):
    s,c=map(int,input().split())
    if ans[s-1]==-1 or ans[s-1]==c:
        ans[s-1]=c
    else:
        print(-1)
        break
else:
    if ans[0]>0 or ans[0]==-1:
        if ans[0]==-1:
            print(1,end="")
        else:
            print(ans[0],end="")
        for i in range(1,n):
            if ans[i]==-1:
                print(0,end="")
            else:
                print(ans[i],end="")
        print()
    else:
        if n==1:
            print(0)
        else:
            print(-1)
    
    