dfs
#include <bits/stdc++.h>
const int maxn = 1000;
const int maxm = 10000;
using namespace std;
int to[maxm+10];
int nex[maxm+10];
int head[maxn+10], cnt = 0;
int know[maxn+10][maxn+10];
int vis[maxn+10];
void dfs(int r, int x)
{
vis[x] = 1;
know[r][x] = know[x][r] = 1;
for (int i = head[x]; i != -1; i = nex[i])
{
int l = to[i];
if (!vis[l])
{
dfs(r, l);
}
}
}
int main()
{
int n, m;
scanf("%d%d", &n, &m);
memset(head, -1, sizeof(head));
for (int i = 1, a, b; i <= m; i++)
{
scanf("%d%d", &a, &b);
to[cnt] = b; nex[cnt] = head[a];
head[a] = cnt++;
}
memset(know, 0, sizeof(know));
for (int i = 1; i <= n; i++)
{
memset(vis, 0, sizeof(vis));
dfs(i, i);
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
bool flag = true;
for (int j = 1; j <= n; j++)
{
if (!know[i][j])
{
flag = false;
break;
}
}
if (flag)
{
ans++;
}
}
printf("%d
", ans);
return 0;
}