#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 7;
bool mark[MAXN];
int n, m, deg[MAXN], rdeg[MAXN], num[MAXN];
vector<int> G[MAXN], rG[MAXN];
void topsort(vector<int> *G, int *d) {
  queue<int> q;
  int left = n;
  for (int u = 1; u <= n; u++)
    if (!d[u]) q.push(u), left--;
  while (q.size()) {
    int u = q.front();
    q.pop();
    if (q.size() == 0)
      num[u] += left;
    else if (q.size() == 1) {
      bool flag = 1;
      for (int v : G[q.front()])
        if (d[v] == 1) flag = 0;
      if (flag)
        num[u] += left;
      else
        mark[u] = 1;
    }
    for (int v : G[u])
      if ((--d[v]) == 0) q.push(v), left--;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, u, v; i < m; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    deg[v]++;
    rG[v].push_back(u);
    rdeg[u]++;
  }
  topsort(G, deg);
  topsort(rG, rdeg);
  int ans = 0;
  for (int u = 1; u <= n; u++)
    if (!mark[u] && num[u] >= n - 2) ans++;
  printf("%d\n", ans);
  return 0;
}
