import sys

n, m = list(map(int, input().split()))
ar = [list(map(int, input().split())) for _ in range(m)]
ans = [0 for _ in range(n)]

for a in ar:
    if a[0] == 1 and a[1] == 0:
        print(-1)
        sys.exit()
    if ans[a[0] - 1] != 0 and ans[a[0] - 1] != a[1]:
        print(-1)
        sys.exit()
    ans[a[0] - 1] = a[1]

if ans[0] == 0:
    if ans[1] == 0:
        ans[1] = 1
    ans[0] = 1

ans = int("".join(map(str, ans)))
print(ans)
