#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long maxx = 0x3f3f3f3f3f3f3f3f;
const long long minn = 0xc0c0c0c0c0c0c0c0;
const double pi = 4.0 * atan(1.0);
#define int long long
#define f(i, n, m) for (long long i = n; i <= m; ++i)
#define unf(i, n, m) for (long long i = n; i >= m; --i)
#define kong NULL
#define debug cout << "sss" << endl;
#define map gp_hash_table
int n, m;
vector<int> mp[100010];
int sum[100010];
map<int, int> cha;
int dfs(int x)
{
if (sum[x] )
return sum[x];
int ans = 0;
cha[x] = 1;
if (mp[x].empty())
return 1;
for (auto it : mp[x])
{
ans += dfs(it);
}
sum[x] = ans;
return ans;
}
int ru[100010];
void solve()
{
cin >> n >> m;
f(i, 1, m)
{
int a, b;
cin >> a >> b;
mp[a].push_back(b);
ru[b]++;
}
int ans = 0;
f(i, 1, n)
{
if (!cha[i] && ru[i] == 0)
ans += dfs(i);
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
solve();
return 0;
}