require 'tsort'

class Hash
  include TSort
  alias tsort_each_node each_key
  def tsort_each_child(node, &block)
    self[node].each(&block)
  end
end

n, m = gets.split.map(&:to_i)
g = Hash[(1..n).map {|i| [i, []] }]
m.times do
  i, j = gets.split.map(&:to_i)
  g[i] << j
end

c = {}
g.each_strongly_connected_component do |sc|
  sc.sort!
  sc.each do |i|
    c[i] = sc
  end
end

(1..n).each do |i|
  puts c[i] * ' '
end
