n,m = map(int,input().split())
ans = list("0"*n)
for i in range(m):
    a,b = map(int,input().split())
    if ans[a-1] == "0" or ans[a-1] == str(b) :
        ans[a-1] = str(b)
    else:
        print("-1")
        exit()
print("".join(ans))