// ---------- begin Strongly Connected Components ----------
struct SCC {
    size: usize,
    edge: Vec<(u32, u32)>,
    id: Vec<usize>,
}

impl SCC {
    pub fn new(size: usize) -> Self {
        SCC {
            size: size,
            edge: vec![],
            id: vec![0; size],
        }
    }
    pub fn add_edge(&mut self, from: usize, to: usize) {
        assert!(from < self.size && to < self.size);
        self.edge.push((from as u32, to as u32));
    }
    fn fill_buffer(&self, buf: &mut [u32], cnt: &[u32]) {
        let mut index = vec![0; self.size];
        let mut sum = 0;
        for (index, c) in index.iter_mut().zip(cnt.iter()) {
            *index = sum;
            sum += *c;
        }
        for &(f, t) in self.edge.iter() {
            let f = f as usize;
            buf[index[f] as usize] = t;
            index[f] += 1;
        }
    }
    fn build_graph<'a>(&self, buf: &'a mut [u32]) -> Vec<&'a mut [u32]> {
        let size = self.size;
        let mut cnt = vec![0; size];
        for e in self.edge.iter() {
            cnt[e.0 as usize] += 1;
        }
        self.fill_buffer(buf, &cnt);
        let mut buf = Some(buf);
        let mut ans = Vec::with_capacity(size);
        for &len in cnt.iter() {
            let len = len as usize;
            let x = buf.take().unwrap();
            let (x, y) = x.split_at_mut(len);
            ans.push(x);
            buf = Some(y);
        }
        ans
    }
    pub fn build(&mut self) {
        let size = self.size;
        let mut buf = vec![0; self.edge.len()];
        let buf = buf.as_mut_slice();
        let graph = self.build_graph(buf);
        let empty = size as u32;
        let mut index = 0;
        let mut ord = vec![empty; size];
        let mut assigned = vec![false; size];
        let mut id = 0;
        let mut stack_s = vec![];
        let mut stack_p = vec![];
        let mut call = vec![];
        for i in 0..size {
            if ord[i] != empty {
                continue;
            }
            enum Operation {
                Call(usize),
                Iterate(usize, usize),
                Eval(usize),
            }
            call.push(Operation::Call(i));
            while let Some(op) = call.pop() {
                match op {
                    Operation::Call(v) => {
                        ord[v] = index;
                        index += 1;
                        stack_s.push(v);
                        stack_p.push(v);
                        call.push(Operation::Eval(v));
                        call.push(Operation::Iterate(v, 0));
                    },
                    Operation::Iterate(v, k) => {
                        for i in k..graph[v].len() {
                            let u = graph[v][i] as usize;
                            if ord[u] == empty {
                                call.push(Operation::Iterate(v, i + 1));
                                call.push(Operation::Call(u));
                                break;
                            } else if !assigned[u] {
                                while let Some(&x) = stack_p.last() {
                                    if ord[x] <= ord[u] {
                                        break;
                                    } else {
                                        stack_p.pop();
                                    }
                                }
                            }
                        }
                    },
                    Operation::Eval(v) => {
                        if *stack_p.last().unwrap() == v {
                            while let Some(u) = stack_s.pop() {
                                assigned[u] = true;
                                self.id[u] = id;
                                if u == v {
                                    break;
                                }
                            }
                            stack_p.pop();
                            id += 1;
                        }
                    },
                }
            }
        }
        for x in self.id.iter_mut() {
            *x = id - 1 - *x;
        }
    }
    pub fn get_array(&self) -> Vec<usize> {
        self.id.clone()
    }
}
// ---------- end Strongly Connected Components ----------

use proconio::*;

fn run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize, usize); m],
    }
    let mut scc = SCC::new(n);
    for (a, b) in e {
        scc.add_edge(a, b);
    }
    scc.build();
    let id = scc.get_array();
    let k = *id.iter().max().unwrap() + 1;
    let mut a = vec![vec![]; k];
    for (i, id) in id.iter().enumerate() {
        a[*id].push(i);
    }
    println!("{}", k);
    for a in a.iter() {
        print!("{}", a.len());
        for a in a {
            print!(" {}", *a);
        }
        println!();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 50604