N, M = map(int, input().split())

result = ["" for _ in range(N)]

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

save = []

result = -1

for n in range(10 ** (N - 1), 10 ** (N)):
    if all([str(n)[e[0] - 1] == str(e[1]) for e in ls]):
        result = n
        break

print(result)
