N, M = map(int, input().split())
q = [list(map(int, input().split())) for i in range(M)]

ans = -1
for i in range(10 ** (N-1), 10 ** N + 1):
  flag = True
  for j in range(M):
    try:
      if str(i)[q[j][0] - 1] != str(q[j][1]):
        flag = False
    except:
      flag = False
      break
      
  if flag:
    ans = i
    break
    
print(ans)
