import sys
lines = sys.stdin.readlines()
line1 = lines.pop(0).split(' ')
N = int(line1[0])
M = int(line1[1])

str = [0, 0, 0]

for i in range(M):
  line = lines.pop(0).split(' ')
  s = int(line[0])
  c = int(line[1])
  str[s-1] = c


if (str[0] != 0):
  ret = int(str[0])*100 + int(str[1])*10 + int(str[2])
  print(ret)
else:
  print(-1)
