n, m = map(int, input().split())
num = ["0", "0", "0"]
tmp = 0
err = 0
for i in range(m):
    s, c = map(int, input().split())
    if tmp != s:
        if s == 1 and c != 0:
            num[0] = str(c)
        elif s == 2 and c != 0:
            num[1] = str(c)
        elif s == 3:
            num[2] = str(c)
        else:
            err += 1
    elif num[tmp-1] == str(c):
        continue
    else:
        err += 1
    tmp = s
guess = "".join(num)
if err == 0:
    for i in range(1000):
        x = str(i).zfill(3)
        if guess == x:
            print(i)
else:
    print("-1")