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

for n in range(10 ** (N - 1), 10 ** N):
    flag = True
    for s, c in X:
        flag &= n // (10 ** (3 - s)) % 10 == c

    if flag:
        print(n)
        break
else:
    print(-1)
