N, M, *SC = map(int, open(0).read().split())

for i in range(10 ** N):
    S = str(i)
    if len(S) == N:
        if all(S[s - 1] == str(c) for s, c in zip(*[iter(SC)] * 2)):
            print(S)
            quit()

print(-1)