from collections import defaultdict

d = defaultdict(int)
ans = 0
n, m = map(int, input().split())
for _ in range(m):
    s, c = map(int, input().split())
    if ((s == 1) & (c == 0)):
        ans = -1
        break
    if s not in d.keys():
        d[s] = c
    elif (d[s] != c):
        ans = -1
        break
if ans == 0:
    for i in range(1, n + 1):
        if (i == 1) & (d[i] == 0):
            ans += 1 * (10 ** (n - i))
        else:
            ans += d[i] * (10 ** (n - i))
print(ans)