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

for i in range(10 ** (n - 1) - 1, 10 ** n):
    j = str(i)
    f = 0
    for s, c in sc:
        if j[s - 1] != str(c):
            break
        f += 1
    if f == m:
        print(i)
        exit()
print(-1)