n, m = map(int, input().split())
T = [list(map(int, input().split())) for i in range(m)]

#for i in range(10 ** (n - 1), 10 ** n):
for i in range(700, 710):
    for j in range(m):
        ans = 0
        if (str(i))[(T[j][0] - 1)] != str(T[j][1]):
            ans = -1
            break
    if ans == 0:
        ans = i
        break

print(ans)
