n, m = map(int, input().split())
sc = sorted([list(map(int, input().split())) for _ in range(m)])

ans = ["*"] * (n)
for s, c in sc:
    if ans[s-1] != "*" and ans[s-1] != str(c):
        print(-1)
        exit()
    else:
        ans[s-1] = str(c)

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

if ans == str(int(ans)):
    print(int(ans))
else:
    print(-1)