n,m = map(int,input().split())

sc =[[str(i) for i in input().split()] for i in range(m)]

ans =[]
x1 = "o"
x2 = "p"
x3 = "q"

for i in range(m):
  if n == 3: #3桁専用
    if sc[i][0] == "1" and (x1 == "o"):
      x1 = str(sc[i][1])
      continue
  
    if sc[i][0] == "1" and (x1 != "o") and (x1 != sc[i][1]) :
      print("-1")
      exit()
    
    if sc[i][0] == "2" and (x2 == "p"):
      x2 = str(sc[i][1])
  
    if sc[i][0] == "2" and (x2 != "p") and (x2 != sc[i][1]):
      print("-1")
      exit()
    
    if sc[i][0] == "3" and (x3 == "q"):
      x3 = str(sc[i][1])
    if sc[i][0] == "3" and (x3 != "q") and (x3 != sc[i][1]):
      print("-1")
      exit()

  if n == 2: #2桁専用
    if sc[i][0] == "1" and (x2 == "p"):
      x2 = str(sc[i][1])
      
  
    if sc[i][0] == "1" and (x2 != "p") and (x2 != sc[i][1]) :
      print("-1")
      exit()
        
    if sc[i][0] == "2" and (x3 == "q"):
      x3 = str(sc[i][1])
  
    if sc[i][0] == "2" and (x3 != "q") and (x3 != sc[i][1]):
      print("-1")
      exit()
        
  if n == 1:#1桁専用
    if sc[i][0] == "1" and (x3 == "q"):
      x3 = str(sc[i][1])
      continue
  
    if sc[i][0] == "1" and (x3 != "q") and (x3 != sc[i][1]) :
      print("-1")
      exit()

      


for j in range(1000):
  j = str(j)
  
  #1桁の場合
  if len(j) == 1:
    if x3 == "q":
      if len(j) == n:
        ans.append(j)
    if x3 != "q":
      if j == x3:
        if len(j) == n:
          ans.append(j)
        
        
  #2桁の場合
  if len(j) == 2:
    #10の位決まってない
    if x2 == "p":
      if x3 == "q":  #1の位決まってない
        if len(j) == n:
          ans.append(j)
      
      if x3 != "q": #1の位決まってる
        if j[1] == x3:
          if len(j) == n:
            ans.append(j)
    
    #10の位決まってる
    if x2 != "p":
      if x3 == "q": #1の位決まってない
        if j[0] == x2:
          if len(j) == n:
            ans.append(j)
      if x3 != "q":
        if j[0] == x2 and j[1] == x3:
          if len(j) == n:
            ans.append(j)#1の位決まってる 
          
          
          
  #3桁の場合
  if len(j) == 3:
    #100の位決まってない
    if x1 == "o":
      if x2 == "p":#10の位決まってない
        if x3 == "q":  #1の位決まってない
          if len(j) == n:
            ans.append(j)
      
        if x3 != "q": #1の位決まってる
          if j[2] == x3:
            if len(j) == n:
              ans.append(j)
      
      
      if x2 != "p":#10の位決まってる
        if x3 == "q": #1の位決まってない
          if j[1] == x2:
            if len(j) == n:
              ans.append(j)
        if x3 != "q":
          if j[1] == x2 and j[2] == x3:
            if len(j) == n:
              ans.append(j)#1の位決まってる 
    
    #100の位決まってる
    if x1 != "o":
      if x2 == "p":#10の位決まってない
        if x3 == "q":#1の位決まってない
          if j[0] == x1:
            if len(j) == n:
              ans.append(j)
      
        if x3 != "q": #1の位決まってる
          if j[0] == x1 and j[2] == x3:
            if len(j) == n:
              ans.append(j)
      
      
      if x2 != "p":#10の位決まってる
        if x3 == "q": #1の位決まってない
          if j[0] == x1 and j[1] == x2:
            if len(j) == n:
              ans.append(j)
        
        if x3 != "q":
          if j[0] == x1 and j[1] == x2 and j[2] == x3:
            if len(j) == n:
              ans.append(j)#1の位決まってる 
    
          
     

         
ans.sort()
if len(ans) > 0:
  print(ans[0])
else:
  print("-1")
    

Measured memory_bytes: 3320