n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    S, C = map(int, input().split())
    s.append(S-1)
    c.append(C)

ans = [9] * n

used = []
for i in range(m):
    if s[i] not in used:
        ans[s[i]] = c[i]
        used.append(s[i])
    else:
        if ans[s[i]] != c[i]:
            ans = [-1]
            break
else:
    for i in range(1, n):
        if i not in used:
            ans[i] = 0

if n != 1 and ans[0] == 0:
    ans = [-1]
if n == 1 and m == 0:
    ans = [0]
for i in range(len(ans)):
    print(ans[i], end="")
