#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef long long ll;
typedef pair<int, int> PII;
const int N = 1e5+10;
int h[4*N],e[2*N],ne[2*N],idx;
bool o[N];
int f[N],n,m,ans;
void add (int a,int b)
{
ne[idx]=h[a],e[idx]=b,h[a]=idx++;
}
void bfs (int x)
{
if (h[x]==-1)
{
ans++;
return;
}
for (int i=h[x];i!=-1;i=ne[i])
{
bfs (e[i]);
}
}
void solve()
{
memset (h,-1,sizeof h);
cin >> n >> m;
int x,y;
while (m--)
{
cin >> x >> y;
add (x,y);
o[y]=true;
}
for (int i=1;i<=n;i++)
if (h[i]!=-1 && !o[i])
bfs (i);
cout << ans <<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}