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

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

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