n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))

list_answer = [0]*n
error_flag = False
for digit in sc:
  if (list_answer[-digit[0]] != 0) and (list_answer[-digit[0]] != digit[1]):
    error_flag = True
  else:
  	list_answer[-digit[0]] = digit[1]
    
if list_answer[0] == 0:
  error_flag = True
if error_flag:
  print(-1)
else:
  tmp = map(str, list_answer)
  ans = "".join(tmp)
  print(ans)