N, M= [int(i) for i in input().split()]
SCm =[[int(i) for i in input().split()] for _ in range(M)]

results = [-1 for _ in range(N)]
impossible = False
for sc in SCm:
  s, c = sc
  if results[s-1] != -1:
    if results[s-1] != c:
      impossible =True
      break
  else:
    results[s-1] = c
if results[0] == 0:
  impossible = True
if impossible:
  print(-1)
else:
  results[0] = max(results[0], 1)
  print(int("".join([str(s if s >=0 else 0) for s in results])))

