N, M = map(int, input().split())
res = ["?" for _ in range(N)]


for _ in range(M):
    s, c = map(int, input().split())
    if res[s - 1] == "?" or res[s - 1] == str(c):
        res[s - 1] = str(c)
    else:
        print(-1)
        exit()

if res[0] == "?":
    res[0] = "1"

for i in range(len(res)):
    if res[i] == "?":
        res[i] = "0"

print(int("".join(res)) if res[0] != "0" else -1)
