#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
const int M = 300010;
int n, m, tot;
int to[M], nxt[M], head[N];
int in[N], out[N], degIn[N], degOut[N], seq[N], u[M], v[M], rel[N], relCnt[N];
vector<int> g[N];
void addEdge(int u, int v) { to[++tot] = v, nxt[tot] = head[u], head[u] = tot; }
void init() {
  memset(degIn, 0, sizeof(degIn));
  memset(degOut, 0, sizeof(degOut));
  for (int i = 1; i <= n; i++) g[i].clear();
  memset(rel, 0, sizeof(rel));
  memset(relCnt, 0, sizeof(relCnt));
}
void topsort() {
  for (int i = 1; i <= m; i++) {
    addEdge(u[i], v[i]);
    degIn[v[i]]++;
  }
  queue<int> q;
  for (int i = 1; i <= n; i++)
    if (degIn[i] == 0) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    seq[++seq[0]] = u;
    for (int i = head[u]; i; i = nxt[i]) {
      int v = to[i];
      degIn[v]--;
      if (degIn[v] == 0) q.push(v);
    }
  }
}
void solve(int *s, int *t, int *ans) {
  init();
  for (int i = 1; i <= m; i++) g[t[i]].push_back(s[i]);
  queue<int> q;
  int cnt = 0;
  for (int j = 1; j <= n; j++) {
    int u = seq[j];
    for (int i = 0, ln = g[u].size(); i < ln; i++) {
      int v = g[u][i];
      degOut[v]++;
      if (degOut[v] == 1) {
        cnt--;
        rel[v] = u;
        relCnt[u]++;
      } else if (rel[v] != -1) {
        relCnt[rel[v]]--;
        rel[v] = -1;
      }
    }
    while (!q.empty() && degOut[q.front()] != 0) q.pop();
    if (cnt == 0)
      ans[u] = 0;
    else if (cnt == 1 && relCnt[q.front()] == 0)
      ans[u] = 1;
    else
      ans[u] = 2;
    cnt++;
    q.push(u);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &u[i], &v[i]);
  topsort();
  solve(u, v, in);
  reverse(seq + 1, seq + n + 1);
  solve(v, u, out);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (in[i] + out[i] < 2) ans++;
  printf("%d\n", ans);
}
