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())
  
max_s=max(s)
ans=-1

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