n, m = [int(x) for x in input().split()]

ans = ["x"] * n

for i in range(m):
    s, c = [int(x) for x in input().split()]
    if ans[s-1] == "x":
        ans[s-1] = str(c)
    elif ans[s-1] != str(c):
        print("-1")
        exit()

if n >= 2 and ans[0] == "0":
    print("-1")
    exit()

ans = ["0" if x == "x" else x for x in ans]

print("".join(ans))