N, M = map(int, input().strip().split())
A = [None for _ in range(N)]
for _ in range(M):
  s, c = map(int, input().strip().split())
  if A[s-1] is None:
    A[s-1] = c
  else:
    if A[s-1] != c:
      print(-1)
      exit()

if A[0] is None or (len(A) >= 2 and A[0] == 0):
  print(-1)
  exit()
A = [str(e) if e else '0' for e in A]
print(''.join(A))
