N, M = map(int, input().split())
keta = []
for _ in range(M):
    keta.append(tuple(map(int, input().split())))

ans = [-1 for _ in range(N)]
for s, c in keta:
    if ans[s - 1] == -1:
        ans[s - 1] = c
    elif ans[s - 1] == c:
        ans[s - 1] = c
    else:
        print(-1)
        break
else:
    for idx, a in enumerate(ans):
        if a == -1:
            ans[idx] = 0
    if len(str(int("".join(map(str, ans))))) == N:
        print(int("".join(map(str, ans))))
    else:
        print(-1)
