#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000009;
const int MAXN = 300 * 1000;
int n, m;
vector<int> graph[2][MAXN + 3];
int deg[3][MAXN + 3];
bool important[MAXN + 3];
bool semi[MAXN + 3], compromise[MAXN + 3];
vector<int> cand[MAXN + 3];
vector<int> V;
int currcand, currmin;
int era[MAXN + 3];
void TopSort() {
  queue<int> Q;
  for (int i = 1; i <= n; i++) {
    if (deg[2][i] == 0) Q.push(i);
  }
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    V.push_back(v);
    for (auto u : graph[0][v]) {
      deg[2][u]--;
      if (deg[2][u] == 0) Q.push(u);
    }
  }
}
void Solve(int ind) {
  set<pair<int, int> > S;
  set<int> affected;
  deg[ind][0] = INF;
  for (int i = 1; i <= n; i++) {
    if (deg[ind][i] == 0) {
      S.insert(make_pair(-1, i));
      era[i] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    int v = V[i];
    S.erase(make_pair(era[v], v));
    if (v == currcand) affected.clear();
    if (S.size() > 0) important[v] = false;
    if (S.size() == 1) {
      int u = S.begin()->second;
      if (currcand != u) {
        currmin = 0;
        currcand = u;
        for (auto z : graph[ind][u]) {
          if (deg[ind][currmin] > deg[ind][z]) currmin = z;
          affected.insert(z);
        }
      }
      if (deg[ind][currmin] > 1)
        cand[v].push_back(u);
      else
        compromise[v] = true;
    }
    if (S.size() > 1) {
      compromise[v] = true;
    }
    for (auto u : graph[ind][v]) {
      deg[ind][u]--;
      if (deg[ind][u] == 0) {
        S.insert(make_pair(i, u));
        era[u] = i;
      }
      if (affected.find(u) != affected.end()) {
        if (deg[ind][currmin] > deg[ind][u]) currmin = u;
      }
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    graph[0][a].push_back(b);
    graph[1][b].push_back(a);
    deg[0][b]++;
    deg[1][a]++;
    deg[2][b]++;
  }
  TopSort();
  for (int i = 1; i <= n; i++) important[i] = true;
  Solve(0);
  reverse(V.begin(), V.end());
  Solve(1);
  for (int i = 1; i <= n; i++)
    semi[i] = (!compromise[i]) &&
              (cand[i].size() == 1 ||
               (cand[i].size() == 2 && (cand[i][0] == cand[i][1])));
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += (important[i] || semi[i]);
  printf("%d\n", ans);
  return 0;
}
