# Strongly Connected Components
class SCC
  attr_accessor(:g, :ng, :rg, :comp, :ord, :used, :size)
  
  def initialize
    @ng = Hash.new
    @rg = Hash.new
    @comp = Hash.new
    @order = []
    @used = Hash.new(false)
  end
  
  def add_edge(u, v)
    @ng[u] ||= []
    @ng[u] << v
    @rg[v] ||= []
    @rg[v] << u
  end
  
  def dfs(cur)
    return if @used[cur]
    @used[cur] = true
    
    @ng[cur] ||= []
    @ng[cur].each {|to| dfs(to) }
    @order << cur
  end
  
  def rdfs(cur, group)
    return if !@comp[cur].nil?
    @comp[cur] = group
    @rg[cur] ||= []
    @rg[cur].each {|v| rdfs(v, group) }
  end
  
  def build
    @ng.keys.each {|k| dfs(k) }
    group = 0
    @order.reverse.each do |u|
      if @comp[u].nil?
        rdfs(u, group)
        group += 1
      end
    end
    
    @size = group
    return @size
  end   
end

n, m = $stdin.readline.chomp.split.map(&:to_i)
scc = SCC.new

m.times do
  a, b = $stdin.readline.chomp.split.map(&:to_i)
  scc.add_edge(a, b)
end

g = scc.build
res = Array.new(g) { Array.new }
scc.comp.each do |k, v|
  res[(v - 1) % g] << k
end

puts g
res.each {|v| puts "%d %s" % [v.size, v.join(" ")] }