#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int n, m, tot, head[N], f[N];
bool v[N];
struct Edge {
  int tot, head[N], suiv[N << 1], ver[N << 1], ind[N];
  inline void lnk(int x, int y) {
    ver[++tot] = y;
    suiv[tot] = head[x];
    head[x] = tot;
    ind[y]++;
  }
} e[2];
inline void solve(int x, int y, int s, int op) {
  bool valid = 1;
  for (int i = e[op].head[y]; i; i = e[op].suiv[i]) {
    int z = e[op].ver[i];
    if (e[op].ind[z] == 1) {
      valid = 0;
      break;
    }
  }
  if (valid)
    f[x] += s;
  else
    v[x] = 1;
}
inline void topo(int op) {
  queue<int> q;
  int sum = 0;
  for (int i = 1; i <= n; i++)
    if (!e[op].ind[i]) q.push(i), sum++;
  while (q.size()) {
    int x = q.front();
    q.pop();
    if (!q.size()) f[x] += n - sum;
    if (q.size() == 1) solve(x, q.front(), n - sum, op);
    for (int i = e[op].head[x]; i; i = e[op].suiv[i]) {
      int y = e[op].ver[i];
      e[op].ind[y]--;
      if (!e[op].ind[y]) q.push(y), sum++;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y; i <= m; i++)
    scanf("%d%d", &x, &y), e[0].lnk(x, y), e[1].lnk(y, x);
  for (int i = 0; i < 2; i++) topo(i);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (!v[i] && f[i] >= n - 2) ans++;
  printf("%d\n", ans);
  return 0;
}
