import sys
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())
if m == 0:
    print(0)
else:
    ans = [10] * max(s)
    for i in range(m):
        if s[i] == 1 and c[i] == 0:
            
                print(-1)
                sys.exit()
        if ans[s[i] - 1] == 10:
            ans[s[i] - 1] = c[i]
        else:
            if c[i] != ans[s[i] - 1]:
                print(-1)
                sys.exit()

    for i in range(len(ans)):
        if i == 0 and ans[i] == 10:
            ans[i] = 1
        elif ans[i] == 10:
            ans[i] = 0
    print(''.join([str(i) for i in ans]))