#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<vector>
using namespace std; const int maxn = ;
const int maxm = ;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-; struct Edge{
int u,v,next;
}edge[ maxn*maxn ];
int cnt,head[ maxn ];
int vis[ maxn ],belong[ maxn ];
stack<int>s;
int dfn[ maxn ],low[ maxn ];
int Cnt ,id ; void init(){
while( !s.empty() )
s.pop();
Cnt = ;
id = ;
memset( dfn,-,sizeof( dfn ) );
memset( low,-,sizeof( low ) );
cnt = ;
memset( head,-,sizeof( head ) );
} void addedge( int a,int b ){
edge[ cnt ].u = a;
edge[ cnt ].v = b;
edge[ cnt ].next = head[ a ];
head[ a ] = cnt++;
} void tarjan( int cur ){
dfn[ cur ] = low[ cur ] = id++;
vis[ cur ] = ;
s.push( cur );
for( int i=head[ cur ];i!=-;i=edge[i].next ){
int nxt = edge[i].v;
if( dfn[ nxt ]==- ){
tarjan( nxt );
low[ cur ] = min( low[ nxt ],low[ cur ] );
}
else if( vis[ nxt ]== ){
low[ cur ] = min( dfn[ nxt ],low[ cur ] );
}
}
if( dfn[ cur ]==low[ cur ] ){
Cnt ++;
while( ){
int tmp = s.top();
s.pop();
vis[ tmp ] = ;
belong[ tmp ] = Cnt;
if( tmp==cur ) break;
}
}
} int main(){
int n,m;
while( scanf("%d%d",&n,&m)== ){
int a,b;
init();
while( m-- ){
scanf("%d%d",&a,&b);
addedge( a,b );
}
for( int i=;i<=n;i++ ){
if( dfn[i]==- ){
tarjan( i );
}
}
printf("缩点 = %d\n",Cnt);
}
return ;
}