N, M = map(int, input().split())
A = [-1] * N
for i in range(M):
  t = list(map(int, input().split()))
  if t == [1, 0] and N != 1:
    print(-1)
    exit()
  elif A[t[0] - 1] == -1:
    A[t[0] - 1] = t[1]
  elif A[t[0] - 1] != t[1]:
    print(-1)
    exit()
B = [A[k] * (10 ** (N - 1 - k)) for k in range(N) if A[k] > 0]
print(sum(B))