import functools

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

ans = [-1] * n

flag = 0

for i in range(m):
    keta = ls[i][0] - 1
    if ls[i] == [1, 0]:
        flag = 1
        break
    else:
        if ans[keta] == -1:
            ans[keta] = ls[i][1]
        elif ans[keta] == ls[i][1]:
            continue
        else:
            flag = 1
            break

if flag == 1:
    print(-1)
elif flag == 0:
    for j in range(n):
        if ans[j] == -1:
            if j == 0:
                ans[j] = 1
            else:
                ans[j] = 0
    ans_n = int(functools.reduce(lambda x, y: x + y, [str(x) for x in ans]))
    print(ans_n)