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 len(set(appear_list[i])) > 1:
    flag = 1
    break
  elif len(set(appear_list[i])) == 1: 
    if appear_list[i][0] == "0" and len(ans) == 0:
      flag = 1
      break
    ans += appear_list[i][0]
  elif len(set(appear_list[i])) == 0: 
    if i == 0:
      flag= 1
      break
    else:
	    ans += "0"
if flag == 0:
  print(int(ans))
else:
  print(-1)
  
  