n,m=map(int,input().split())
sc=[tuple(map(int,input().split())) for _ in range(m)]
for i in range(1000):
  if not len(str(i))==n:
    continue
  for s,c in sc:
    if not str(i)[s-1]==str(c):
      break
  else:
    print(i)
    exit()
print(-1)