#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7, M = N;
int n, m;
int f[N], st[N];
struct Graph {
  int edge[M], succ[M], ver[N], idx;
  int deg[N];
  void add(int u, int v) {
    edge[idx] = v;
    succ[idx] = ver[u];
    ver[u] = idx++;
    ++deg[v];
  }
  void topo() {
    queue<int> q;
    int des = 0;
    for (int i = 1; i <= n; ++i)
      if (!deg[i]) q.push(i), ++des;
    while (!q.empty()) {
      int u = q.front(), sz = q.size();
      q.pop();
      if (sz == 1)
        f[u] += n - des;
      else if (sz == 2) {
        int y = q.front();
        int flag = 0;
        for (int i = ver[y]; ~i; i = succ[i]) {
          int v = edge[i];
          if (deg[v] == 1) {
            flag = 1;
            break;
          }
        }
        if (flag)
          st[u] = 1;
        else
          f[u] += n - des;
      }
      for (int i = ver[u]; ~i; i = succ[i]) {
        int v = edge[i];
        if (--deg[v] == 0) q.push(v), ++des;
      }
    }
  }
} g, r_g;
int main() {
  memset(g.ver, -1, sizeof g.ver);
  memset(r_g.ver, -1, sizeof r_g.ver);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g.add(u, v);
    r_g.add(v, u);
  }
  g.topo();
  r_g.topo();
  int res = 0;
  for (int i = 1; i <= n; ++i)
    if (!st[i] && f[i] >= n - 2) ++res;
  printf("%d", res);
  return 0;
}
