N,M = map(int, input().split())
S = []
C = []
for i in range(M):
    s,c = map(int, input().split())
    S.append(s)
    C.append(c)
for n in range(1000):
    if len(str(n))==N:
        count = 0        
        if n==0:
            l=[0]
        else:
            l = []
            while n > 0:
                l.append(n%10)
                n //= 10
            l.reverse()
                
        for i in range(M):     
            if(l[S[i]-1] == C[i]):
                count += 1
            
        if count == M:
            break
else:
    n=-1
    
print(n)            