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

ans = ["*"] * (n)
for s, c in sc:
    if ans[s-1] != "*" and ans[s-1] != str(c):
        print(-1)
        exit()
    else:
        ans[s-1] = str(c)

ans = "".join(ans).replace("*", str(0))

if ans == str(int(ans)):
    print(int(ans))
else:
    print(-1)