#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int rd() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch ^ 48);
    ch = getchar();
  }
  return x * w;
}
int to[N << 1], nt[N << 1], hd[N], tot = 1;
void adde(int x, int y) { ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot; }
int n, m, ee[N][2], dg[N], a[N], sq[N], ts, ti, tn;
queue<int> q;
void wk(int o) {
  for (int i = 2; i <= tot; ++i) ++dg[to[i]];
  for (int i = 1; i <= n; ++i)
    if (!dg[i]) q.push(i);
  ti = n;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    --ti;
    if (q.empty())
      a[x] += ti;
    else if (q.size() == 1) {
      a[x] += ti - 1;
      int y = q.front();
      for (int i = hd[y]; i; i = nt[i])
        if (dg[to[i]] == 1) {
          a[x] -= ti - 1;
          break;
        }
    }
    for (int i = hd[x]; i; i = nt[i]) {
      int y = to[i];
      --dg[y];
      if (!dg[y]) q.push(y);
    }
  }
}
int main() {
  n = rd(), m = rd();
  for (int i = 1; i <= m; ++i) ee[i][0] = rd(), ee[i][1] = rd();
  for (int i = m; i; --i) adde(ee[i][0], ee[i][1]);
  wk(1);
  memset(hd, 0, sizeof(int) * (n + 1)), tot = 1;
  for (int i = 1; i <= m; ++i) adde(ee[i][1], ee[i][0]);
  wk(0);
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans += a[i] >= n - 2;
  printf("%d\n", ans);
  return 0;
}
