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


    
    
        
