N,M = list(map(int, input().split()))
s = []
c = []
for i in range(M):
  inputs = list(map(int, input().split()))
  s.append(inputs[0])
  c.append(inputs[1])

res = [0 for i in range(N)]
for digit, number in zip(s,c):
  digit -= 1
  res[digit] = number

convert = list(map(str, res))
res = int("".join(convert))
if len(str(res)) == N:
  print(res)
else:
  print(-1)
