#include<bits/stdc++.h>
using namespace std;
int n,m;
bool f[105][105];
int main()
{
freopen("contest.in","r",stdin);
freopen("contest.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
f[x][y]=true;
}
for (int k=1;k<=n;k++)
for (int x=1;x<=n;x++)
for (int y=1;y<=n;y++)
f[x][y]=(f[x][k]&&f[k][y])||f[x][y];
int Ans=0;
for (int i=1;i<=n;i++)
{
int cnt=0;
for (int j=1;j<=n;j++)
if (f[i][j]||f[j][i])
cnt++;
if (cnt==n-1)
Ans++;
}
printf("%d\n",Ans);
return 0;
}