#include <bits/stdc++.h>
using namespace std;
int n, m, tsort[100005], k, x, y;
vector <int> v[100005], inv[100005], sol[100005];
bool u[100005];
void dfs(int q){
u[q] = 1;
for (auto it: v[q])
if (!u[it]) dfs(it);
tsort[++k] = q;
}
void dfsinv(int q){
u[q] = 0;
for (auto it: inv[q])
if (u[it]) dfsinv(it);
sol[x].push_back(q);
}
int main(){
ifstream cin ("ctc.in");
ofstream cout ("ctc.out");
cin >> n >> m;
for (int i=1; i<=m; i++){
cin >> x >> y;
v[x].push_back(y);
inv[y].push_back(x);
}
for (int i=1; i<=n; i++){
if (!u[i]) dfs(i);
}
x = 0;
for (int i=n; i; i--)
if (u[tsort[i]]) x++, dfsinv(tsort[i]);
cout << x << "\n";
for (int i=1; i<=x; i++){
for (auto it: sol[i]) cout << it << " ";
cout << "\n";
}
return 0;
}