require 'set'

class Graph
	def initialize
		@nodes = Set.new
		@edges = Set.new
	end
	attr_reader :nodes, :edges

	def add_node(label = nil)
		Node.new(label)
	end

	def add_edge(u, v)
		e = Edge.new(u, v)
		u.outgoings << e
		v.incomings << e
		e
	end
	
	def del_edge(e)
		u, v = e.from, e.to
		u.outgoings.delete(e)
		v.incomings.delete(e)
		e
	end

	class Node
		def initialize(label)
			@label = label
			@outgoings = Set.new
			@incomings = Set.new
		end

		def to_nodes
			@outgoings.map(&:to)
		end

		def from_nodes
			@incomings.map(&:from)
		end

		
		def to_s
			@label
		end
		attr_accessor :incomings, :outgoings
		attr_reader :label
	end

	class Edge
		def initialize(u, v)
			@from = u	
			@to = v
		end
		attr_reader :from, :to
	end

	def Graph::get_path_bfs(s, t)
		path_edge = {}
		reached = Set[s]
		queue = [s]
		while !queue.empty? 
			u = queue.shift
			u.outgoings.each{|e|
				v = e.to
				next if reached.include?(v)	
				reached << v
				queue << v
				path_edge[v] = e

				if v == t
					path = []
					while e = path_edge[v]
						path.unshift e
						v = e.from
					end
					return path
				end
			}
		end	
		return nil
	end

	def Graph::get_path_dfs(s, t, reached = Set.new)
		reached << s	
		s.outgoings.each{|e|
			v = e.to
			next if reached.include?(v)
			return [e] if v == t
			
			path = get_path_dfs(v, t, reached) 
			return [e] + path if path
		}
		nil
	end

	def Graph::reachable_from(s, reached = Set.new, root = true)
		reached << s	
		s.outgoings.each{|e|
			v = e.to
			next if reached.include?(v)
			reachable_from(v, reached, false) 
		}
		root ? reached : nil
	end

	def Graph::layers_from(s)
		reached = Set[s]
		layers = [[s]]

		loop {
			layers << []
			layers[-2].each{|u|
				u.to_nodes.each{|v|
					next if reached.include?(v)
					reached << v
					layers[-1] << v
				}
			}	

			if layers[-1].empty?
				layers.pop
				return layers
			end
		}
	end
end

class Forest < Graph #graphs whose max in-degree <= 1
	def add_node(label = nil)
		Node.new(label)
	end

	def add_edge(u, v)
		raise "multiple in-edge" unless v.incomings.empty?
		e = Edge.new(u, v)
		u.outgoings << e
		v.incomings << e
		e
	end

	class Node < Graph::Node
		def parent
			a = incomings.to_a.map(&:from)
			a.empty? ? nil : a[0]
		end

		def compute_height
			@height = 0
			return if @outgoings.empty?

			to_nodes.each(&:compute_height)	
			h = to_nodes.map(&:height).max
			@outgoings.reject!{|e| e.to.height < h}

			@height = h + 1
		end

		attr_reader :height
	end

	class Edge < Graph::Edge
	end
end


g = Forest.new
n, m = gets.split.map(&:to_i)

nodes = (1..n).map{|i| g.add_node(i) }
edge_idx = {}
m.times{|k|
	i, j = gets.split.map(&:to_i)
	g.add_edge(nodes[i-1], nodes[j-1])
	edge_idx[[i, j]] = k + 1
}

roots = nodes.select{|v| v.incomings.empty?}
roots.each{|v| v.compute_height}
h = roots.map(&:height).max
roots.reject!{|v| v.height < h}

if roots.size != 1
	p -1
else
	ans = []
	Graph::layers_from(roots[0]).each_cons(2){|l1, l2|
		if l1.size == 1 && l2.size == 1
			ans << edge_idx[[l1[0].label, l2[0].label]]
		end
	}
	puts ans.sort
end