N, M= map(int, input().split())
si=[];ci=[]

for i in range(M):
    s, c=map(int,input().split())
    if( (s in si) and (s!=1) ):
            si[si.index(s)]=min(si[si.index(s)],s)
    elif((s in si) and (s==1) and (c!=0)):
            si[si.index(s)]=min(si[si.index(s)],s)        
    elif((s in si)==False):
        si.append(s)
        ci.append(c)
n=0
if( 1 in si ):
    if(ci[si.index(1)]==0):
        print('-1')        
    else:
        for j in range(len(si)):
            n+=ci[j]*10.0**(N-si[j])
        print(int(n))    
else:
    print('-1')