N=io.read"*n"
M=io.read"*n"
sc={}
for i=1,M do
  sc[i]={io.read("*n","*n")}
end
table.sort(sc,function(a,b)return a[1]<b[1]end)
function f(sc)
  r={}
  for _,v in ipairs(sc) do
    if(v[1]==1)then
	  if(v[2]==0)then return -1 end
    end
    if(r[v[1]] and r[v[1]]~=v[2])then return -1 end
    r[v[1]]=v[2]
  end
  if(r[1]==nil)then r[1]=1 end
  for i=2,N do
    if(r[i]==nil)then r[i]=0
  end
end
print(f(sc))