N,M=map(int,input().split())
if M!=0:
    a=[list(map(int,input().split())) for i in range(M)]
    ans=0
    for i in range(M):
        if ans==-1:
            break
        for j in range(M):
            if a[i][0]==a[j][0] and a[i][1]!=a[j][1]:
                ans=-1
                break
#print(ans)####      
    answer=[0]*N
    for i in range(M):
        answer[a[i][0]-1]=a[i][1]
    
    if answer[0]==0 and N>=2:
        ans=-1
#print(answer)######
    if ans==-1:
        print(ans)
    elif answer[0]==0 and N==1:
        print("0")
    else:
        ans=0
        for i in range(N):
            ans+=answer[i]*(10**(N-i-1))
        print(ans)
else:
    if N!=1:
        print(10**(N-1))
    else:
        print("0")