n,m = map(int, input().split())
s_and_c = []
for i in range(m):
    s_and_c.append(list(map(int, input().split())))

ans = ["-1" for i in range(n)]
s_and_c.sort()


if m == 0:
    if n == 1:
        ans = ["0"ß]
    else:
        ans[0] = "1"

elif n != 1 and s_and_c[0][0] == 1 and s_and_c[0][1] == 0:
    ans = -1
else:
    for i in range(m):
        if ans[s_and_c[i][0] - 1] == "-1":
            ans[s_and_c[i][0] - 1] = str(s_and_c[i][1])
        elif ans[s_and_c[i][0] - 1] == str(s_and_c[i][1]):
            continue
        else:
            ans = -1


if ans != -1:
    for i in range(n):
        if ans[i] == "-1":
            ans[i] = "0"
    ans = "".join(ans)

print(ans)
