N, M = list(map(int, input().split()))
B = {}
for i in range(M):
  k, v = list(map(int, input().split()))
  if k in B:
    if B[k]==v:
      pass
    else:
      print(-1)
      exit()
  else:
    B[k] = v
ans = ""
for i in range(1, N+1):
  if i==1 and B.get(i, 0)==0:
      print(-1)
      exit()    
  ans = ans + str(B.get(i, 0))
print(ans)