n, m = map(int, input().split())

listans = ["0"] * n
ans = "0"

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

if listans[0] == "0":
    ans = "-1"

if ans == "0":
        ans = str(int("".join(listans)))

print(ans)