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

S = [0] * M
C = [0] * M

for i in range(M):
    S[i], C[i] = input().split()

ans = -1
for i in range(10 ** (N - 1), 10 ** N):
    for s, c in zip(S, C):
        if not str(i)[int(s) - 1] == c:
            break
    else:
        ans = i
        break
    if not ans == -1:
        break

print(ans)