import sys
N, M = map(int, input().split())
line = []
for i in range(M):
  line.append([int(i) for i in input().split()])
for i in range(10 ** N):
  i_keta = [i // 100, (i % 100) // 10, i % 10]
  correct = True
  for test in line:
    s = test[0]
    c = test[1]
    if s == 1:
      if N >= 2:
        if i_keta[3 - N] == 0 or i_keta[3 - N] != c:
          correct = False
          break
      elif i_keta[2] != c:
        correct = False
        break
    else:
      if i_keta[s - N + 2] != c:
        correct = False
        break
  if correct:
    if N >= 2 and i_keta[3 - N] != 0:
      print(i)
      sys.exit(1)
    elif N == 1:
      print(i)
      sys.exit(1)
print(-1)