import numpy as np

num = list(map(int,input().split()))

matrix = np.ones(num[0]) * (-1)
sign_0 = []
sign_1 = []
ans = 0

if num[1] == 0:
  if not matrix[0] == 0:
    ans = 10**(num[0]-1)
  elif matrix[0] == 0:
    ans = -1

elif not num[1] == 0:
  for i in range(0,num[1]):
    temp = list(map(int,input().split()))
    if (temp[0] in sign_0) and (temp not in sign_1) :
      ans = -1
      break
    else:
      matrix[temp[0]-1] = temp[1]
      sign_0.append(temp[0])
      sign_1.append(temp)
  
  if not ans == -1:
    if matrix[0] == -1:
       matrix[0] = 1
        
    for i in range(1,num[0]):
      if matrix[i] == -1:
        matrix[i] = 0
        
    ans = matrix[0]*(10**(num[0]-1))
    
    for i in range(1,num[0]):
      ans = ans + matrix[i]*(10**(num[0]-1-i))
    ans = int(ans)
      
  judge_a = len(list(str(ans)))
  judge = judge_a - num[0]
  
  if not judge == 0:
    ans = -1
    
  
print(ans)