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 = [0] * 3
for i in range(m):
    if ans[s[i] - 1] != 0:
        if ans[s[i] - 1] >= 10:
            continue
        else:
            if ans[s[i] - 1] != c[i]:
                print(-1)
                exit()
    else:
        ans[s[i] - 1] += c[i]
if ans[0] == 0:
    print(-1)
    exit()
print("".join(map(str, ans)))
