N, M = map(int, input().split())
s = []
for n in range(0, M):
  s.append(list(map(lambda x: int(x), input().split())))

answer = [-1] * N

for n in s:
  index = n[0] - 1
  if answer[index] == -1:
  	answer[index] = n[1]
  else:
    if answer[index] != n[1]:
      print("-1")
      exit()

if answer[0] == -1:
  answer[0] = 1
if answer[0] == 0:
  print("-1")
  exit()
      
for n in range(0, len(answer)):
  if answer[n] == -1:
    answer[n] = 0
      
ans_string = ""
for n in answer:
  ans_string += str(n)

print(ans_string)