require 'set'

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

g = {}
g_inv = {}

(0..n-1).each do |i|
	g[i] = Set.new
	g_inv[i] = Set.new
end

roots = Set[*(0..n-1).to_a]
m.times do
	i, j = gets.split.map(&:to_i)
	roots.delete(j)
	g[i] << j
	g_inv[j] << i
end

flip = {}
roots.each do |r0|
	used_roots = [r0]
	f = 0

	until used_roots.size == roots.size
		dist = {}
		used_roots.each do |r|
			dist[r] = 0
		end

		d = 0
		loop do
			stack = (0..n-1).select {|u| dist[u] == d}
			break if stack.empty?
			until stack.empty?
				u = stack.pop
				g[u].each do |v|
					next if dist[v]
					dist[v] = dist[u]
					stack << v
				end
			end

			(0..n-1).each do |u|
				next unless dist[u] == d
				g_inv[u].each do |v|
					next if dist[v]
					dist[v] = d + 1
				end
			end

			d += 1
		end

		r = (roots - used_roots).min_by {|u| dist[u]}
		f += dist[r]
		used_roots << r
	end

	flip[r0] = f
end

min_f = flip.values.min
min_by = (0..n-1).select {|u| flip[u] == min_f}
puts [min_by.size, min_f] * ' '
puts min_by * ' '