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

ans = [None] * n
for i in range(m):
    s, c = map(int, input().split())
    if ans[s - 1] is None:
        ans[s - 1] = c
    else:
        print(ans[s-1],c)
        ans[s - 1] = min(ans[s - 1], c)
    print(ans)

ansp = ""
if ans[0] is None and n == 1:
    print("0")
if ans[0] is None or ans[0] == 0:
    print("-1")
else:
    for i in range(n):
        if ans[i] is None:
            ans[i] = 0
        ansp += str(ans[i])
    print(ansp)

