info = [int(n) for n in input().split()]

number = [0, 0, 0]
answer = 0

for i in range(info[1]):
  n = [int(n) for n in input().split()]
  target_number = number[n[0]- 1]
  if target_number is 0:
    number[n[0]- 1] = n[1]
  else:
    if target_number != n[1]:
      answer = -1
      print(answer)
      break

if answer != -1:
  answer = number[0]*100 + number[1]*10 + number[2]
  print(answer)