import sys                                                   
N, M = map(int, input().split())                             
                                                             
                                                             
sc = dict()                                                  
for i in range(M):                                           
  s, c = map(int, input().split())                           
  if s in sc and sc[s] != c:                                 
    print(-1)                                                
    break                                                    
  sc[s] = c                                                  
else:                                                        
  i1 = sc.get(3, -1)                                         
  i2 = sc.get(2, -1)                                         
  i3 = sc.get(1, -1)                                         
                                                             
  for k in range(1, int(10 ** N)):                           
    k, k1 = divmod(k, 10)                                    
    k, k2 = divmod(k, 10)                                    
    k, k3 = divmod(k, 10)                                    
    if (                                                     
      (N == 1 and k2 == 0 and k3 == 0 and k1) or             
      (N == 2 and k3 == 0 and k2) or                         
      (N == 3 and k3)                                        
    ):                                                       
      if (                                                   
        (i1 == -1 or k1 == i1) and                           
        (i2 == -1 or k2 == i2) and                           
        (i3 == -1 or k3 == i3)                               
      ):                                                     
        print(int(k3 * 100 + k2 * 10 + k1))                  
        break                                                
  else:                                                      
    print(-1)                                                
                                                             
                                                             