n, m = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(m)]
for i in range(1000):
  t = str(i)
  l = len(t)
  if l != n:
    continue
  for s, c in SC:
    if s > l or t[s-1] != str(c):
      break
  else:
    print(i)
    break
else:
  print(-1)