N,M=map(int,input().split())
C=[-1]*N
ans=0
for i in range(M):
    s,c=map(int,input().split())
    if(s>N):
        ans=-1
    else:
        if(C[s-1]!=-1):
            if(C[s-1]!=c):
                ans=-1
        else:
            C[s-1]=c
if(C[0]==0):
    ans=-1

if(ans!=-1):
    for i in range(N):
        if(i==0):
            if(C[i]==-1):
                C[i]=1
        else:
            if(C[i]==-1):
                C[i]=0
    #print(C)
    for j in range(N):
        ans+=C[j]*(10**(N-1-j))
if(N==1 and C[0]==0):
    ans=0
print(ans)
