N, M = map(int, input().split())
s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = map(int, input().split())

ans = [-1]*N
b = True

for i in range(M):
    if(ans[s[i]-1] != -1 and ans[s[i]-1] != c[i]):
        b = False
        break
    ans[s[i]-1] = c[i]
    
if(b==False or ans[0]==0):
    b = False
else:
     for i in range(len(ans)):
            if(ans[i] == -1):
                ans[i] = 0
if(b):
    ans_print = ""
    for i in range(len(ans)):
        ans_print += str(ans[i])
    print(ans_print)
else:
    print("-1")