N, M = map(int, input().split())
Q = [list(map(int, input().split())) for i in range(M)]


for n in range(1000):
    X = list(map(int, list(str(n))))
    for s, c in Q:
        s -= 1
        if len(X) != N:
            break

        if X[s] != c:
            break
    else:
        print(n)
        exit()

print(-1)
