#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, m, w, F[N], D[N], M[N], C[N];
vector<int> T, Adj[2][N];
set<int> S;
void DFS(int v) {
  M[v] = 1;
  for (int &u : Adj[w][v])
    if (!M[u]) DFS(u);
  T.push_back(v);
}
void Solve() {
  S.clear();
  T.clear();
  memset(M, 0, sizeof(M));
  memset(D, 0, sizeof(D));
  memset(C, 0, sizeof(C));
  for (int i = 1; i <= n; i++)
    if (!M[i]) DFS(i);
  reverse(T.begin(), T.end());
  for (int i = 0; i < (int)T.size(); i++) {
    int &v = T[i];
    for (int &u : Adj[!w][v]) {
      if (D[u] == 0) S.erase(u);
      if (D[u] == 1)
        for (int &r : Adj[w][u]) C[r]--;
      D[u]++;
      if (D[u] == 1)
        for (int &r : Adj[w][u]) C[r]++;
    }
    if ((int)S.size() == 0) {
      S.insert(v);
      F[v] += i + 1;
      continue;
    }
    if ((int)S.size() > 1) {
      S.insert(v);
      continue;
    }
    int u = *S.begin();
    if (C[u] == 0) F[v] += i;
    S.insert(v);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    Adj[0][v].push_back(u);
    Adj[1][u].push_back(v);
  }
  w = 0;
  Solve();
  w = 1;
  Solve();
  int c = 0;
  for (int i = 1; i <= n; i++)
    if (F[i] >= n) c++;
  printf("%d", c);
  return (0);
}
