from sys import exit

n, m = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(m)]
ans = [10] * n
tmp = []

for i in arr:
    for j in arr:
        if i[0] == j[0] and i[1] != j[1]:
            print(-1)
            exit()
    s = i[0] - 1
    c = i[1]
    ans[s] = min(ans[s], c)

for i, num in enumerate(ans):
    if num == 10 and i == 0:
        ans[i] = 1
    elif num == 10 and i != 0:
        ans[i] = 0

if ans[0] == 0 and len(ans) != 1:
    print(-1)
else:
    print(*ans, sep="")
