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 k3 in range(10):                                            
    if i3 != -1 and i3 != k3:                                     
      continue                                                    
    for k2 in range(10):                                          
      if i2 != -1 and i2 != k2:                                   
        continue                                                  
      for k1 in range(10):                                        
        if i1 != -1 and i1 != k1:                                 
          continue                                                
        if (                                                      
            (N == 3 and k3) or                                    
            (N == 2 and not k3 and k2) or                         
            (N == 1 and not k3 and not k2 and k1)                 
          ):                                                      
          print(int(k3 * 100 + k2 * 10 + k1))                     
          sys.exit(1)                                             
  print(-1)                                                       