n, m = map(int, input().split())

x = y = z = ans = 0

for _ in range(m):
    s, c = map(int, input().split())
    if s == 1 and c != 0 and (x == 0 or x == c):
        x = c
    elif s == 2 and (y == 0 or y == c):
        y = c
    elif s == 3 and (z == 0 or z == c):
        z = c
    else:
        ans = -1
print(x*100+y*10+z if ans == 0 else ans)
