def search(i, dim, nodes1, parent, found)
  if nodes1[parent] != []
    nodes1[parent].each do |kid|
      if kid == i && dim > 1
        found[0] = 1
        return true
      end
    end
    nodes1[parent].each do |kid|
      dim += 1
      search(i, dim, nodes1, kid, found)
    end
  end
  dim -= 1
end

n, m  = gets.split.map(&:to_i)
nodes0 = Array.new(n).map{Array.new}
nodes1 = Array.new(n).map{Array.new}

(n - 1 + m).times do
  start, goal = gets.split.map(&:to_i)
  nodes0[goal - 1]  << start - 1
  nodes1[start - 1] << goal - 1
end

n.times do |i|
  x = nodes0[i].size
  if x > 1
    x.times do |j|
      found = [0]
      search(i, 1, nodes1, nodes0[i][j], found)
      if found[0] == 1
        nodes0[i][j] = -1
      end
    end
  end
end

nodes0.each do |node|
  if node == []
    puts 0
  else
    node.each do |a|
      if a != -1
        puts a + 1
      end
    end
  end
end
