#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
//存图
struct vv{
int to, next;
}G[N];
int head[N], cnt;
inline void add(int from, int to){
G[++cnt].to = to;
G[cnt].next = head[from];
head[from] = cnt;
}
//tarjan算法模板
//可以用来找图中的联通分量
//所谓联通分量指的是在图中的子图顶点能两两到达则是联通分量
int dfn[N], low[N];
bool vis[N];
stack st;
int tot;
void tarjan(int x){
dfn[x] = low[x] = ++tot;
st.push(x);
vis[x] = 1;
for(int e = head[x]; e; e = G[e].next){
int to = G[e].to;
if(!dfn[to]){
tarjan(to);
low[x] = min(low[x], low[to]);
}else if(vis[to]){
low[x] = min(low[x], dfn[to]);
}
}
if(low[x] == dfn[x]){
int now;
do{
now = st.top();
st.pop();
vis[now] = 0;
cout << now << ’ ';
}while(x != now);
cout << ‘\n’;
}
}
void init(int n){
for(int i = 1; i <= n+10; i++){
dfn[i] = 0; low[i] = 0;
vis[i] = 0; head[i] = 0;
}
cnt = 0; tot = 0;
}
int main(){
// freopen(“C:\freopen\input.txt”, “r”, stdin);
int n, m;
cin >> n >> m;
init(n);
for(int i = 1; i <= m; i++){
int u, v;
cin >> u >> v;
add(u, v);
}
for(int i = 1; i <= n; i++){
if(!dfn[i]) tarjan(i);
}
}