N, M = map(int, input().split())
memory = [-1]*N
ans = 1
for i in range(M):
  s, c = map(int, input().split())
  s -= 1
  if s == 0 and c == 0:
    ans = -1
    continue
  elif memory[s] == -1:
    memory[s] = c
  else:
    if memory[s] == c:
      continue
    else:
      ans = -1
      break

if ans == -1 or memory[0] == -1:
  print(-1)
else:
  for i in range(N):
    if memory[i] == -1:
       memory[i] = 0
  memory = [str(num) for num in memory]
  output = "".join(memory)
  print(int(output))
    