# C
n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    ss, cc = map(int, input().split())
    s.append(ss)
    c.append(cc)
    
bool = True
ans = [-1]*n
for i in range(m):
    if ans[s[i]-1] == -1 or ans[s[i]-1] == c[i]:
        ans[s[i]-1] = c[i]
    else:
        bool = False
        break
        
if bool == False or ans[0] == -1 or ans[0] == 0:
    print(-1)
else:
    for j in range(n):
        if ans[j] == -1:
            ans[j] = 0
    for v in ans:
        print(v, end='')