x,y=gets.split.map!(&:to_i)
s=Array.new(y)
c=Array.new(y)
dame=0
ame=0
ans=Array.new(x,0)
if x>1
  ans[0]=1
end
for i in 0..y-1
  s[i],c[i]=gets.split.map!(&:to_i)
  if s[i]==1 && c[i]==0
    ame=1
  else
    ans[s[i]-1]=c[i]
  end
end
for i in 0..y-1
  for j in 0..y-1
    if s[i]==s[j]
      if c[i]!=c[j]
        dame=1
      end
    end
  end
end
if dame==1 || ame=1
  if x==1 && dame==1
    puts 0
  else
    puts -1
  end
else
  for k in 0..x-1
  print(ans[k])
  end
end
