n, m = map(int, input().split())

sc = [list(map(int, input().split())) for i in range(m)]

k = 0

ans = [-5]*n

for i in range(m):
    if ans[sc[i][0]-1] == -5:
        ans[sc[i][0]-1] = sc[i][1]
    elif ans[sc[i][0]-1] != sc[i][1]:
        k = 1
    else:
        continue

if k == 1:
    print(-1)
elif ans[0] == 0:
    if n == 1:
        print(0)
    else:
        print(-1)
else:
    for i in range(3):
        if ans[i] == -5:
            ans[i] = 0
    if ans[0] == 0:
        ans[0] = 1
    ans = [str(i) for i in ans]
    ans = "".join(ans)
    print(int(ans))