N,M=map(int, input().split())
S={}
ans=0
if M!=0:
    for _ in range(M):
        s,c=map(int, input().split())
        if (s not in S) or (S[s]==c):
            S[s]=c
        else:
            ans=-1
    if ans!=-1:
        for s in S.keys():
            ans+=S[s]*10**(N-s)
        if len(str(ans))!=N:
            ans=-1
else:
    if N==1:
        ans=0
    else:
        ans=-1
print(ans)