N,M=map(int,input().split())
d = dict()
for i in range(M):
  a,b=map(int,input().split())
  if a not in d:
    d[a]=b
  else:
    if d[a]!=b:
      print(-1)
      exit(0)
tmp=0
for i in range(10):
  if N==3 and i ==0:
    continue
  for j in range(10):
    if N==2 and j ==0:
      continue
    for k in range(10):
      if 1 in d and d[1] != i:
        continue
      if 2 in d and d [2] != j:
        continue
      if 3 in d and d[3]!= j:
        continue
      print((str(i)+str(j)+str(k))[3-N:])
      exit(0)
        
      
    