N,M=map(int,input().split())
candi=["na"]*N
ans=0

for i in range(M):
    s,c=(map(int, input().split()))
    if candi[s-1]=="na":
        candi[s-1]=c
    elif candi[s-1]!=c:
        ans=-1



if ans==-1:
    pass
elif candi[0]==0:
    ans=-1
else:
    for k,num in enumerate(candi):
        if k==0 and num=="na":
            ans+=1*10**(N-1)
        elif num=="na":
            ans+=0
        elif num!="na":
            ans+=int(num)*10**(N-k-1)

print(ans)