#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int n,m,q[103][103],answer=0;
int main()
{
freopen ("contest.in","r",stdin);
freopen ("contest.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
{
for (int j=1;j<=n;j++)
{
q[i][j]=-1;
}
}
for (int k=0;k<m;k++)
{
int a,b;
scanf("%d%d",&a,&b);
q[a][b]=1;
}
for (int k=1;k<=n;k++)
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (q[i][k]!=-1&&q[k][j]!=-1)
q[i][j]=q[i][k]+q[k][j];
for (int o=1;o<=n;o++)
{
int c=0;
for (int u=1;u<=n;u++)
{
if (o!=u)
{
if (q[o][u]!=-1)
{
c++;
}
else
{
if (q[u][o]!=-1)
c++;
}
}
}
if (c>=n-1)
answer++;
}
cout<<answer;
return 0;
}