n,m=map(int,input().split())
sc={}
ans=""
for i in range(m):
    s,c=map(int,input().split())
    if s in sc:
        if c!=sc[s]:
            ans=-1
    else:
        sc[s]=c
if ans!=-1:
    for i in range(n):
        if i+1 in sc:
            ans+=str(sc[i+1])
        else:
            ans+="0"
ans=int(ans)
if ans==0 or len(str(ans))!=n:
    ans = -1
print(ans)