import sys
N,M = map(int, input(). split())

s = [0,]*M
c = [0,]*M
ans =[10,]*N




for i in range(M):
    s[i], c[i] = map(int, input(). split())
    if ans[s[i]-1] != 10 and ans[s[i]-1] != c[i]:
        print(-1)
        sys.exit()
    else:
        ans[s[i]-1] = c[i]       

if N == 1:
    print(0)        
        
else:
    A = 0  
    print(ans)
    if ans[0] == 0:
        print(-1)
        sys.exit()
    elif ans[0] == 10:
        ans[0] = 1
        for j in range(N):
            if ans[j] == 10:
                ans[j] = 0
        for k in range(N):
            A += 10**(N-k-1)*ans[k] 
    
        print(A)
    

        
    else:
        for j in range(N):
            if ans[j] == 10:
                ans[j] = 0
        for k in range(N):
            A += 10**(N-k-1)*ans[k] 
        print(A)
    
    


    