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