import sys

N, M = map(int, input().split())
li = [list(map(int, input().split())) for n in range(M)]

ans = [0] * N

for i in li:
  if ans[i[0]-1] != 0 and ans[i[0]-1] != i[1]:
    print(-1)
    sys.exit()

  ans[i[0]-1] = i[1]

if ans[0] == 0:
  print(-1)
  sys.exit()
else:
  print(int("".join([str(n) for n in ans])))