N,M=map(int,input().split())
ans=[-1]*N
sc=[list(map(int,input().split())) for i in range(M)]
cnt=0
for i in range(M):
    if ans[sc[i][0]-1]==-1:
        ans[sc[i][0]-1]=sc[i][1]
    else:
        if ans[sc[i][0]-1]!=sc[i][1]:
            cnt+=1
if cnt>0:
    print(-1)
elif ans[0]==0:
    print(-1)
else:
    s=''
    for i in range(N):
        if ans[i]==-1:
            if i==0:
                ans[i]=1
            else:
                ans[i]=0
        s+=str(ans[i])
    print(int(s))