N, M = list(map(int, input().split()))
suuji = [-1 for _ in range(N)]

for _ in range(M):
  s, c = list(map(int, input().split()))
  if any([suuji[s-1] not in [-1, c], s > N, all([s==1, c==0, N>1])]):
    print(-1)
    break
  else:
    suuji[s-1] = c
else:
  for i in range(N):
    if suuji[i] == -1:
      suuji[i] = 0
  print(int(''.join([str(i) for i in suuji])))