n, m = map(int, input().split())
l = [-1] * n
ans = 0
for _ in range(m):
    a, b = map(int, input().split())
    a = a - 1
    if l[a] == -1:
        l[a] = b
    elif l[a] == b:
        continue
    else:
        ans = -1
        break

if ans == -1:
    print(ans)
elif n > 1 and l[0] == 0:
    print(-1)
elif l[0] == 0:
    print(0)
else:
    for i in range(n):
        if i == 0 and l[0] == -1:
            l[0] = 1
        elif l[i] == -1:
            l[i] = 0

        ans += l[i] * (10 ** (n - i - 1))

    print(ans)
