# frozen_string_literal: true

$n = gets.chomp.to_i

$m = gets.chomp.to_i

$all = (1..$n).to_a

$graph = {}

$nodes = []
$m.times do
  s, t = gets.chomp.split(' ').map(&:to_i)

  $graph[s] ||= []
  $graph[s] << t
  $nodes << t
end

$stack = $all - $nodes

$res = []
uniq = true
until $stack.empty?
  uniq = false if $stack.length != 1 && uniq
  team = $stack.pop

  $res << team

  next unless $graph[team]

  $graph[team].each do |t|
    $stack << t unless $graph.any? { |k, l| k != team && l.include?(t) }
  end
  $graph.delete(team)
end

puts $res.join("\n")

puts uniq ? 0 : 1

