N,M=map(int,input().split())
s=[0]*M
c=[0]*M

for i in range(M):
  s[i],c[i]= map(int,input().split())
  
if M>0:
  max_s=max(s)
else:
  max_s=100
ans=-1

for j in range(1000):
  flag=True
  k=str(j)  
  if len(k)<max_s:
    pass
  else:
    if len(k)!=N:
      pass
    else:
      if M>0:
        for l in range(M):
          if int(k[s[l]-1])!=c[l]:
            flag=False
            break
        if flag==True:
          if ans==-1:
            ans=j
          else:
            ans=min(ans,j)
          break
      else:
        pass
      
print(ans)