N, M = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(M)]
minN = 0 if N == 1 else 10 ** (N - 1)

for t in range(minN, 10 ** N):
    for s, c in C:
        if (t // (10 ** (N - s))) % 10 != c:
            break
    else:
        ans = t
        break
else:
    ans = -1

print(ans)
