n,m = map(int,input().split())

A = [-1]*n

ans = 0

for i in range(m):
    
    s,c = map(int,input().split())
    
    if A[s-1] == -1 or A[s-1] == c:
        A[s-1] = c
          
    else:
        print(-1)
        break
    
else:
    if A[0] == -1:
        A[0] = 1
        
    if A[0] == 0:
        print(-1)
        
    else:
        
        for i in range(n):
            
            if A[i] == -1:
                A[i] = 0
                
            ans = ans*10 +A[i]
        
        print(ans)