N,M=map(int,input().split())
L=["" for i in range(N)]
#print(L)
if N==1 and M==0:
    print(0)
    exit()
for i in range(M):
    a,b=map(int,input().split())
    if a==1 and b==0:
        print(-1)
        exit()
    if L[a-1]=="":
        L[a-1]=b
    else:
        if L[a-1]==b:
            continue
        else:
            print(-1)
            exit()

for i in range(N):
    if i==0:
        if L[i]=="":
            L[i]=1
    else:
        if L[i]=="":
            L[i]=0
        
ans=0
for i in range(N):
    ans+=L[i]*10**(N-1-i)
print(ans)