#include <bits/stdc++.h>
#pragma GCC optimize "-O3"
using namespace std;
const int N = 3e5 + 1;
vector<int> g[N];
int n, m;
int ans[N];
int deg[N];
void work(int *fr, int *to) {
  int num = n;
  queue<int> q;
  memset(deg, 0, sizeof deg);
  for (int i = 1; i <= n; ++i) g[i].clear();
  for (int i = 0; i < m; ++i) g[fr[i]].push_back(to[i]), ++deg[to[i]];
  for (int i = 1; i <= n; ++i)
    if (!deg[i]) q.push(i), num--;
  while (q.size()) {
    int u = q.front();
    q.pop();
    if (q.empty())
      ans[u] += num;
    else {
      if (q.size() == 1) {
        bool ch = 1;
        for (int v : g[q.front()]) ch &= (deg[v] > 1);
        ans[u] += ch * num;
      } else
        ans[u] -= N;
    }
    for (int v : g[u])
      if (!(--deg[v])) q.push(v), num--;
  }
}
int fr[N], to[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) cin >> fr[i] >> to[i];
  work(fr, to);
  work(to, fr);
  int res = 0;
  for (int i = 1; i <= n; ++i) res += (ans[i] + 2 >= n);
  cout << res << endl;
}
