from sys import exit
n, m = map(int, input().split())

if m == 0:
    if n == 1:
        print(0)
    else:
        print(10 ** (n - 1))
    exit()

X = ["" for _ in range(n)]
for _ in range(m):
    s, c = map(int, input().split())
    if X[s - 1] == "" or X[s - 1] == str(c):
        X[s - 1] = str(c)
    else:
        print(-1)
        exit()
ans = ""
for x in X:
    if x == "":
        ans += "0"
    else:
        ans += x
ans = int(ans)
if n == 1:
    print(ans if 0 <= ans < 10 else - 1)
else:
    print(ans if 10 ** (n - 1) <= ans < 10 ** n else - 1)