#include <bits/stdc++.h>
#define eps 1e-8
#define ll long long
#define INF 2147483647
#define ll_INF 9223372036854775807
using namespace std;
inline int read() {
int x = 0,tmp = 1;char ch = getchar();
while( ch < '0' || ch > '9' ) {if ( ch == '-' ) tmp = -1; ch = getchar();}
while( ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar(); }
return x * tmp;
}
bool _edge[110][110];
int main() {
memset( _edge, 0, sizeof( _edge ) );
int N = read(), M = read();
for( int i = 1 ; i <= M ; ++ i ) {
int u = read(), v = read();
_edge[u][v] = 1;
}
for( int k = 1 ; k <= N ; ++ k )
for( int i = 1 ; i <= N ; ++ i )
for( int j = 1 ; j <= N ; ++ j )
_edge[i][j] = ( _edge[i][k] && _edge[k][j] ) || _edge[i][j];
int ans = 0;
for( int i = 1 ; i <= N ; ++ i ) {
int cnt = 0;
for( int j = 1 ; j <= N ; ++ j ) cnt += _edge[j][i];
for( int j = 1 ; j <= N ; ++ j ) cnt += _edge[i][j];
ans += ( cnt == N - 1 );
}
printf( "%d\n", ans );
return 0;
}