table = Array.new(100001).map{[]}
n,m = gets.split(" ").map{|d| d.to_i}

m.times do
	a,b = gets.split(" ").map{|d| d.to_i}
	table[a] << b
end

cnt = 0
1.upto(n) do |i|
	q = []
	table[i].each do |t|
		q << t
		while q.empty? == false
			t2 = table[q.shift]
			if t2.length == 1
				q << t2[0]
			elsif t2.length > 1
				puts i 
				cnt += 1
				break
			end
		end
	end
end

puts -1 if cnt == 0