#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int ver[N << 2], nxt[N << 2], head[N << 2], tot;
int u[N], v[N], f[N], vis[N], deg[N], n, m, res, ret;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
void add(int x, int y) {
  ver[++tot] = y;
  nxt[tot] = head[x];
  head[x] = tot;
}
void solve(int x, int y, int cnt) {
  int flag = 0;
  for (int i = head[y]; i; i = nxt[i]) {
    int z = ver[i];
    if (deg[z] == 1) {
      flag = 1;
      break;
    }
  }
  if (flag)
    vis[x] = 1;
  else
    f[x] += cnt;
}
void topsort() {
  queue<int> q;
  ret = 0;
  for (int i = 1; i <= n; i++) {
    if (!deg[i]) {
      q.push(i);
      ++ret;
    }
  }
  while (!q.empty()) {
    int x = q.front(), num = q.size();
    q.pop();
    if (num == 1) {
      f[x] += n - ret;
    }
    if (num == 2) {
      int y = q.front();
      solve(x, y, n - ret);
    }
    for (int i = head[x]; i; i = nxt[i]) {
      int y = ver[i];
      --deg[y];
      if (!deg[y]) q.push(y), ++ret;
    }
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    u[i] = read();
    v[i] = read();
    add(u[i], v[i]);
    deg[v[i]]++;
  }
  topsort();
  tot = 0;
  memset(head, 0, sizeof(head));
  for (int i = 1; i <= m; i++) {
    add(v[i], u[i]);
    deg[u[i]]++;
  }
  topsort();
  for (int i = 1; i <= n; i++) {
    if (!vis[i] && f[i] >= n - 2) ++res;
  }
  printf("%d\n", res);
}
