N,M=map(int, input().split())
A=[0]*(N)
ans=0
for m in range(M):
    s,c=map(int, input().split())
    s=s-1
    if (A[s]!=0) and (A[s]!=c):
        ans=-1
    else:
        A[s]=c
if ans!=-1:
    lenA=len(A)
    if (lenA==1) and (A[0]==0):
        ans=0
    else:
        for a in range(lenA):
            ans=ans+A[a]*10**(N-1-a)
        if ans==0:
            ans=-1
print(ans if ans!=-1 else -1)