N, M = map(int, input().split())
S = [-1] * N
for _ in range(M):
  s, c = map(int, input().split())
  if S[s-1] != -1 and S[s-1] != c:
    print (-1)
    break
  else:
    S[s-1] = c
else:
  if S[0] == 0:
    print (-1)
  else:
    for i in range(N):
      print (S[i] if S[i] != -1 else 0, end="")