#include <bits/stdc++.h>
using namespace std;
template <class T>
static inline void cin_vector(unsigned long long N, vector<T>& v) {
  for (unsigned long long i = 0; i < N; i++) {
    T a;
    cin >> a;
    v.push_back(a);
  }
}
template <class T>
T gcd(T a, T b) {
  if (b > a) {
    swap(a, b);
  }
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
long long N, M;
void solve(vector<long long>& cnt, const vector<long long>& us,
           const vector<long long>& vs) {
  vector<long long> d(N + 1, 0);
  vector<vector<long long>> g(N + 1);
  long long beneath = N;
  for (long long i = 0; i < M; i++) {
    g[us[i]].push_back(vs[i]);
    d[vs[i]]++;
  }
  queue<long long> q;
  for (long long i = 1; i <= N; i++) {
    if (d[i] == 0) {
      q.push(i);
      beneath--;
    }
  }
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    if (q.size() == 0) {
      cnt[u] += beneath;
    } else if (q.size() == 1) {
      bool flag = 1;
      const long long x = q.front();
      for (long long y : g[x]) {
        if (d[y] <= 1) {
          flag = false;
          break;
        }
      }
      if (flag) {
        cnt[u] += beneath;
      }
    }
    for (long long v : g[u]) {
      d[v]--;
      if (d[v] == 0) {
        q.push(v);
        beneath--;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cout.precision(8);
  cin >> N >> M;
  vector<long long> us(M);
  vector<long long> vs(M);
  vector<long long> cnts(N + 1);
  for (long long i = 0; i < M; i++) {
    cin >> us[i] >> vs[i];
  }
  solve(cnts, us, vs);
  solve(cnts, vs, us);
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    if (cnts[i] >= N - 2) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
