from sys import exit
n, m = map(int, input().split())
X = ["" for _ in range(10)]
for _ in range(m):
    c, s = map(int, input().split())
    if X[c] != "" and X[c] != str(s):
        print(-1)
        exit()
    X[c] = str(s)
flag = False
for i in range(1, 11):
    if X[-i] == "":
        if flag:
            X[-i] = "0"
    else:
        flag = True
X = int("".join(X))
print(X if 10 ** (n - 1) <= X < 10 ** n else - 1)