N, M = map(int, input().split())
X = [list(map(int, input().split())) for i in range(M)]
ans =[]
X.sort(reverse = True)

for i in range(N):
  if i == 0:
    ans.append(1)
  
  else:
    ans.append(0)

if M <= 1:
  for j in range(M):
    if X[j][0] == 1:
      if ans[X[j][0]-1] == X[j][1] or ans[X[j][0]-1] == 1:
        ans[X[j][0]-1] = X[j][1]
      
      else:
        ans = '-1'
        break
      
    else:
      if ans[X[j][0]-1] == X[j][1] or ans[X[j][0]-1] == 0:
        ans[X[j][0]-1] = X[j][1]
      
      else:
        ans = '-1'
        break 
    
if M > 1:
  for k in range(M-1):
    if X[k][0] == X[k+1][0] and X[k][1] != X[k+1][1]:
      ans = '-1'
      break
    
    else:
      for j in range(M):
        if X[j][0] == 1:
          if ans[X[j][0]-1] == X[j][1] or ans[X[j][0]-1] == 1:
            ans[X[j][0]-1] = X[j][1]
      
          else:
            ans = '-1'
            break
      
        else:
          if ans[X[j][0]-1] == X[j][1] or ans[X[j][0]-1] == 0:
            ans[X[j][0]-1] = X[j][1]
      
          else:
            ans = '-1'
            break
    
if N >= 2 and ans[0] == 0:
  print(-1)
  
else:
  ansstr = list(map(str, ans))
  ans = ''.join(ansstr)
  print(int(ans))