n,m=map(int,input().split())
sis,cis=[],[]
for i in range(m):
  si,ci=map(int,input().split())
  sis.append(si)
  cis.append(ci)
  
for i in range(10**(n-1),1000):
  counter=0
  for j in range(m):
    si,ci=sis[j],cis[j]
    if len(str(i))>=si and str(i)[si-1]==str(ci):
      counter+=1
  if counter==m:
    if m==0 and n==1:
      print(0)
    else:
      print(i)
    break
else:
  print(-1)