N,M=input().split(" ")
N=(int)(N)
M=(int)(M)

sc={}

for i in range(M):
    sc[i]=-1

check=True

for i in range(M):
    si,ci = input().split(" ")
    si = (int)(si)
    ci = (int)(ci)
    if sc[si-1]!=-1 and sc[si-1]!=ci:
        check = False
        break
    else:
        sc[si-1]=ci
#print(si)
if check and sc[0]!=0:
    ans=""
    if sc[0]==-1:
        ans+= "1"
    else:
        ans+=str(sc[0])
    
    for i in range(M-1):
        if sc[i+1]==-1:
            ans+="0"
        else:
            ans+=(str)(sc[i+1])
    print(ans)
else:
    print(-1)