N, M = map(int, input().split())
list = [0, 0, 0]
flag = 0
for i in range(M):
  s, c = map(int, input().split())
  if s == 4 - N:
    if c == 0:
      flag = 1
    elif list[3 - N] == 0:
      list[3 - N] = c
    elif list[3 - N] != c:
      flag = 1
  else:
    if list[s - 1] == 0:
      list[s - 1] = c
    elif list[s - 1] != c:
      flag = 1
if flag:
  print(-1)
else:
  if list[3 - N] == 0:
    list[3 - N] = 1
  answer = 100 * list[0] + 10 * list[1] + list[2]
  print(answer)
      