(n, m) = [int(s) for s in input().split()]

p = []

for i in range(0, m):
    p.append([int(s) for s in input().split()])

ans = -1
for i in range(0, 1000):
    r = True
    for (s, c) in p:
        si = str(i)
        if len(si) != n or len(si) <= s - 1 or si[s-1] != str(c):
            r = False
            break

    if r:
        ans = i
        break

print(ans)
