N, M = [int(x) for x in input().split()]
s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = [int(x) for x in input().split()]

ans = ["x"] * N

for i in range(M):
    if ans[s[i] - 1] == "x":
        ans[s[i] - 1] = str(c[i])
    elif ans[s[i] - 1] == str(c[i]):
        continue
    else:
        ans = ["-1"]
        break

if ans != ["-1"]:
    for j in range(N):
        if ans[j] == "x":
            ans[j] = "0"

ans = "".join(ans)
if int(ans) == 0 and len(ans) > 1:
    ans = "-1"

print(ans)
