N, M = [int(s) for s in input().split()]
holder = ["undef" for i in range(N)]
judge = True
for i in range(M):
  si, ci = [int(s) for s in input().split()]
  if holder[si-1] != "undef":
    if holder[si-1] != ci:
      judge = False
      break
  if holder[si-1] == "undef":
     holder[si-1] = ci
if holder[0] == 0:
  judge = False

if judge:
  num_str = ""
  for i, s in enumerate(holder):
    if i == 0:
      if s == "undef":
        num_str = num_str + str(1)
      else:
        num_str = num_str + str(s)
    else:
      if s == "undef":
        num_str = num_str + str(0)
      else:
        num_str = num_str + str(s)
  print(num_str)
else:
  print(-1)