N, M = map(int, input().split())
ans = [None] * N
for _ in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] in [None, c]:
        ans[s - 1] = c
    else:
        print(-1)
        quit()

ans = "".join(map(lambda n :str(n) if n else "0", ans))
if N > 1 and ans[0] == "0":
    print(-1)
    quit()

print(ans)
