import sys
N,M = map(int, input(). split())
s = [0,]*M
c = [0,]*M
ans =[10,]*M 
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 ans[0] == 0:
    print(-1)
    sys.exit()
elif ans[0] == 10:
    ans[0] = 1
    A = 0
    for j in range(N):
        if ans[j] == 10:
            ans[j] = 0
    for k in range(N):
        A += 10**(M-(k+1))*ans[k] 
    print(A)
        
else:
    A = 0
    for j in range(N):
        if ans[j] == 10:
            ans[j] = 0
    for k in range(N):
        A += 10**(M-(k+1))*ans[k] 
    print(A)
    
    


    