N,M=map(int,input().split())
count=0
A=[[] for i in range(3)]
for i in range(M):
    s,c=map(int,input().split())
    if s==1 and c==0:
        count+=1
    else:
        A[s-1].append(c)
B=[]
for i in range(N-1,-1,-1):
    if len(A[i])>=1:
        B.append(A[i][0])
        for j in range(1,len(A[i])):
            if A[i][j]!=A[i][0]:
                count+=1
    else:
        B.append(0)
if count>0:
    print(-1)
elif N==1:
    print(B[0])
elif N==2:
    print(B[2]*(10**(N-1))+B[1]*(10**(N-2)))
else:
    print(B[2]*(10**(N-1))+B[1]*(10**(N-2))+B[0])