N,M = map(int, input().split())
appear_list = [[]for i in range(N)]
flag = 0
for i in range(M):
  s,c = map(int, input().split())
  appear_list[s-1].append(str(c))
ans = ""
for i in range(len(appear_list)):
  if i == 0:
    if len(set(appear_list[i])) == 1 and int(appear_list[i][0]) >= 1:
	    ans += appear_list[i][0]
    else:
      if i == N-1 and len(set(appear_list[i])) == 1 and int(appear_list[i][0]) == 0:
        ans += "0"
      else:
      	flag = 1
      	break
  if i >=1:
    if len(set(appear_list[i])) > 1:
      flag = 1
      break
    else:
      if len(set(appear_list[i])) == 1:
        ans += appear_list[i][0]
      else:
        ans += "0"
if flag == 0:
  print(int(ans))
else:
  print(-1)
  
  