N,M = map(int,input().split())
A = [0]*N
for _ in range(M):
    s,c = map(int,input().split())
    if s == 1 and c == 0: 
        print(-1)
        exit()
    if A[s-1] !=0 and A[s-1] != c:
        print(-1)
        exit()
    A[s - 1] = c
zeros = 0
if A[0] == 0:
    print(-1)
    exit()
for  a in A:
    if a == 0: zeros+=1
if zeros > len(A):
    print(-1)
    exit()
ans = 0
for a in A:
    ans+=a
    ans*=10
print(ans//10)
        
    
    


    
    
        