N,M = map(int, input().split())
A=[-1 for i in range(N)]

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

head_0=True
for i in range(N):
    if A[i]==-1:
        if head_0:
            A[i]=""
        else:
            A[i]=0        
    elif A[i]==0:
        if head_0:
            ans=False
        else:
            pass
    else:
        head_0=False
            
if ans and not head_0:
    A=[str(a) for a in A]
    print("".join(A))
elif head_0 and N==1:
    print(0)
else:     
    print(-1)
