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

for i in range(1000):
    ans = str(i)
    for s, c in sc:
        print(s, c, ans)
        if int(ans[s-1]) != c:
            break
    else:
        print(ans)
        exit()

print(-1)