n, m = map(int, input().split())
r = [""] * n
for _ in range(m):
    s, c = input().split()
    s = int(s)-1
    if (r[s] == ""):
        r[s] = c
    elif (r[s] != c):
        print(-1)
        exit()
if r[0] == "":
    print("1", end="")
elif r[0] == "0":
    if (n == 1):
        print(0)
        exit()
    print(-1)
    exit()
else:
    print(r[0], end="")
for i in range(1, n):
    if r[i] == "":
        print("0", end="")
    else:
        print(r[i], end="")
