N, M = map(int, input().split())
rslt = [-1]*N
for m in range(M):
  s, c = map(int, input().split())
  if s > N:
    print(-1)
    exit()
  elif rslt[s-1] != -1 and rslt[s-1] != c:
    print(-1)
    exit()
  else:
    rslt[s-1] = c
if rslt[0] == 0:
  print(-1)
  exit()
rslt = ['0' if i == -1 else str(i) for i in rslt]
print(''.join(rslt))
  