N, M = list(map(int, input().split()))

v_min = list(map(int, list(str(10 ** (N - 1)))))

S = []
for i in range(M):
  s, c = list(map(int, input().split()))
  if s not in S:
  	v_min[s-1] = c
  elif v_min[s-1] != c:
    v_min = -1
    break
  S.append(s)
    
print("".join(map(str,v_min)))