N,M=map(int,input().split())
INF=10**18
A=[INF]*N
ans=0
if M>=1:
    for _ in range(M):
        s,c=map(int,input().split())
        s-=1
        if A[s]==INF:
            A[s]=c
        else:
            if A[s]!=c:
                print(-1)
                exit()
            else:
                continue

if N==1:
    if A[0]==INF:
        A[0]=0
else:    
    if A[0]==0:
        print(-1)
        exit()
    elif A[0]==INF:
        A[0]=1

    for num in A:
        if num==INF:
            num=0
        
A=[str(a) for a in A]
print(''.join(A))