#include <bits/stdc++.h>
using namespace std;
vector<int> u;
vector<int> v;
vector<int> d;
vector<int> c;
long long n, m;
void solve(vector<int> a, vector<int> b) {
  d.resize(n, 0);
  vector<int> vect[n];
  for (int i = 0; i < a.size(); i++) {
    vect[a[i]].push_back(b[i]);
    d[b[i]]++;
  }
  queue<int> q;
  long long x, y, tot = n;
  for (long long i = 0; i < n; i++) {
    if (!d[i]) q.push(i), tot--;
  }
  while (q.size()) {
    x = q.front();
    q.pop();
    if (q.empty())
      c[x] += tot;
    else if (q.size() == 1) {
      long long r = 1;
      y = q.front();
      for (long long i = 0; i < vect[y].size(); i++) r &= (d[vect[y][i]] > 1);
      c[x] += (r * tot);
    }
    for (long long i = 0; i < vect[x].size(); i++)
      if (!--d[vect[x][i]]) q.push(vect[x][i]), tot--;
  }
}
int main() {
  cin >> n >> m;
  c.resize(n);
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    u.push_back(x - 1);
    v.push_back(y - 1);
  }
  solve(u, v);
  solve(v, u);
  long long coun = 0;
  for (long long i = 0; i < c.size(); i++) {
    if (c[i] + 2 >= n) coun++;
  }
  cout << coun;
}
