n, m = map(int, input().split())
d = {}
for _ in range(m):
    s, c = map(int, input().split())
    if (s == 1 and c == 0) or (s in d and d[s] != c):
        print(-1)
        exit()
    d[s] = c
ans = ''
for idx in range(1, n + 1):
    ans += str(d.get(idx, 0))
print(int(ans))