n,m=map(int,input().split())
tf=1
ans=[set()for i in range(n)]
for i in range(m):
    s,c=map(int,input().split())    
    if s==1 and c==0:
        tf=0
    ans[s-1].add(c)
if not tf:
    print(-1)
else:
        
    f=1
    an=''
    #print(ans)
    ii=0
    for i in ans:
        if ii==0 and len(i)==0:
            an+='1'
            ii+=1
            continue
        ii+=1    
        if len(i)>1:
            f=0
            break
        if len(i)==0 and ii!=0:
            an+='p'
        else:
            an+=str(i.pop())
        
    if not f:
        print(-1)
    else:
        an=an.replace('p','0')
        if an[0]=='0':
            print(-1)
        else:    
            print(an)
    
        
        
        
        
