N, M = map(int, input().split())
q = [list(map(int, input().split())) for i in range(M)]
change = [0 for i in range(N)]

ans = list('0' * N)
for i in range(M):
  if change[q[i][0]-1] == 0:
  	ans[q[i][0] - 1] = q[i][1]
  	change[q[i][0]-1] = 1
  else:
    if ans[q[i][0] - 1] != q[i][1]:
      ans = -1
      break
      
try:
  res = ''
  for i in range(len(ans)):
    res += ans[i]
  print(int(res))
except:
  print(-1)
