n,m=map(int,input().split())
ans=["x"]*n

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

if n==1 and ans[0]==0:
    print(0)
    exit()
elif n>1 and ans[0]==0:
    print(-1)
    exit()
    
ans2=["0" if t=="x" else str(t) for t in ans]
print ("".join(ans2))