using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static List<int>[] li,lir,lid,lig;
	static bool[] b;
	static int kk=0,km=0;
	static int[] h,zt;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int n=s[0];
		li=new List<int>[n+1];
		lir=new List<int>[n+1];
		b=new bool[n+1];
		kk=n-1;
		for(int i=1;i<=n;i++){li[i]=new List<int>();lir[i]=new List<int>();}
		for(int i=0;i<s[1];i++){
			var e=sc.Ia;
			e[0]++;
			e[1]++;
			li[e[0]].Add(e[1]);
			lir[e[1]].Add(e[0]);
		}
		h=new int[n];
		for(int i=1;i<=n;i++){if(!b[i]){Fud1(i);}}
		b=new bool[n+1];
		zt=new int[n+1];
		for(int i=0;i<n;i++){
			if(!b[h[i]]){
				km++;
				Fud2(h[i]);
			}
		}
		lid=new List<int>[km+1];
		lig=new List<int>[km+1];
		for(int i=1;i<=km;i++){lid[i]=new List<int>();lig[i]=new List<int>();}
		for(int i=1;i<=n;i++){
			for(int j=0;j<li[i].Count;j++){if(zt[i]!=zt[li[i][j]]){lid[zt[i]].Add(zt[li[i][j]]);}}
			lig[zt[i]].Add(i);
		}
		for(int i=1;i<=km;i++){lid[i]=lid[i].Distinct().ToList();}
		StringBuilder sb=new StringBuilder();
		sb.Append(km+"\n");
		for(int i=1;i<=km;i++){
			sb.Append(lig[i].Count);
			for(int j = 0;j<lig[i].Count;j++) {sb.Append(" "+(lig[i][j]-1));}
			sb.Append("\n");
		}
		Console.Write(sb);
	}
	static void Fud1(int a){
		b[a]=true;
		for(int i=0;i<li[a].Count;i++){if(!b[li[a][i]]){Fud1(li[a][i]);}}
		h[kk--]=a;
	}
	static void Fud2(int a){
		zt[a]=km;
		b[a]=true;
		for(int i=0;i<lir[a].Count;i++){if(!b[lir[a][i]]){Fud2(lir[a][i]);}}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 235000