import numpy as np
N , M = map(int, input().split())
ans = np.zeros(N)
S = []
C = []
for _ in range(M):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)
  if s in S and C[S.index(s)] != c:
    print(-1)
    quit()
  ans[s-1] = c
if ans[0] == 0:
  print(-1)
  quit()
else:
  print(int("".join([str(int(x)) for x in ans])))