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