import java.util.*;
import java.lang.*;
import java.io.*;
public class Main{
static int n = 5000; // Máxima cantidad de nodos
static int dfs_low[] = new int[n];
static int dfs_num[] = new int[n];
static boolean visited[] = new boolean[n];
static Stack<Integer> s;
static int dfsCont, cantSCC;
static ArrayList
<Integer
> ady
[] = new ArrayList[n
];
Scanner sc
= new Scanner
( System.
in );
int v, e, i, a, b;
v = sc.nextInt();
e = sc.nextInt();
//LIMPIAR ADYACENCIAS
for( i = 0; i < v; i++ ){
ady[i] = new ArrayList<Integer>();
}
while( e > 0 ){
e--;
a = sc.nextInt();
b = sc.nextInt();
ady[a].add(b);
}
for( i = 0; i < v; i++ ){
visited[i] = false;
dfs_num[i] = -1;
}
s = new Stack<Integer>();
dfsCont = 0;
cantSCC = 0;
tarjanSCC(0);
}
public static void tarjanSCC( int u ){
dfs_low[u] = dfs_num[u] = dfsCont;
dfsCont++;
s.push(u);
visited[u] = true;
int j, v;
for( j = 0; j < ady[u].size(); j++ ){
v = ady[u].get( j );
if( dfs_num[v] == -1 ){
tarjanSCC( v );
}
if( visited[v] ){
dfs_low
[u
] = Math.
min( dfs_low
[u
], dfs_low
[v
] ); }
}
if( dfs_low[u] == dfs_num[u] ){
cantSCC++;
System.
out.
println("COMPONENTE CONEXA #" + cantSCC
); while( !s.empty() ){
v = s.peek();
s.pop();
visited[v] = false;
if( u == v ) break;
}
}
}
}
aW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgpwdWJsaWMgY2xhc3MgTWFpbnsKCQoJc3RhdGljIGludCBuID0gNTAwMDsgLy8gTcOheGltYSBjYW50aWRhZCBkZSBub2RvcwoJc3RhdGljIGludCBkZnNfbG93W10gPSBuZXcgaW50W25dOwoJc3RhdGljIGludCBkZnNfbnVtW10gPSBuZXcgaW50W25dOwoJc3RhdGljIGJvb2xlYW4gdmlzaXRlZFtdID0gbmV3IGJvb2xlYW5bbl07CglzdGF0aWMgU3RhY2s8SW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