#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  register int x, op = 1, c;
  while (c = getchar(), c < '0' || c > '9')
    if (c == '-') op = -op;
  x = c ^ 48;
  while (c = getchar(), c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48);
  return x * op;
}
int head[300001], nxt[600001], ver[600001], tot = 0;
void add(int x, int y) { ver[++tot] = y, nxt[tot] = head[x], head[x] = tot; }
int n, m;
int ans = 0;
struct edge {
  edge* nxt;
  int ver;
} * h[300001];
int dg[300001] = {0};
void add_edge(int x, int y) {
  edge* p = new edge;
  p->nxt = h[x], p->ver = y;
  h[x] = p;
  dg[y]++;
}
queue<int> q;
bool b[300001] = {0};
int f[300001] = {0};
void check(int x, int y, int w) {
  for (edge* i = h[y]; i; i = i->nxt)
    if (dg[i->ver] == 1) return void(b[x] = 1);
  f[x] += w;
}
int cnt = 0;
void topo() {
  for (int i = 1; i <= n; i++)
    if (!dg[i]) q.push(i), cnt++;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    if (q.empty()) f[x] += n - cnt;
    if (q.size() == 1) check(x, q.front(), n - cnt);
    for (edge* i = h[x]; i; i = i->nxt)
      if (!(--dg[i->ver])) q.push(i->ver), cnt++;
  }
}
int main() {
  n = gi(), m = gi();
  for (int i = 1, x, y; i <= m; i++) x = gi(), y = gi(), add(x, y);
  for (int x = 1; x <= n; x++)
    for (int i = head[x]; i; i = nxt[i]) add_edge(x, ver[i]);
  topo();
  cnt = 0;
  for (int i = 1; i <= n; i++) h[i] = NULL;
  for (int x = 1; x <= n; x++)
    for (int i = head[x]; i; i = nxt[i]) add_edge(ver[i], x);
  topo();
  for (int i = 1; i <= n; i++)
    if (!b[i] && f[i] >= n - 2) ans++;
  printf("%d\n", ans);
  return 0;
}
