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)
elif n>1 and ans[0]==0:
    print(-1)
elif "x" not in ans:
    print ("".join(ans))
    
else:
    for j in range(n):
        if ans[j]=="x":
            ans[j]=0
        print(ans[j], end="")
            
