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

ans = [''] * N
for i in range(M):
  s, c = map(int, input().split())
  if ans[s-1] == '' or ans[s-1] == c:
    ans[s-1] = c
  else:
    print(-1)
    quit()


if ans[0] == '':
  ans[0] = 1
for i in range(1, N):
  if ans[i] == '':
    ans[i] = 0

ans = ans[::-1]
res = 0
digit = 1
for a in ans:
  res += a*digit
  digit *= 10

if len(str(res)) != N:
  print(-1)
else:
  print(res)