N, M = map(int, input().split())

digit = ["-1"] * N
for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    if digit[s] != "-1" and str(c) != digit[s]:
        print(-1)
        exit()
    digit[s] = str(c)

if digit[s] == "0" and N != 1:
    print(-1)
    exit()

for i in range(N):
    if digit[i] == "-1":
        digit[i] = "0"
print(int("".join(digit)))