#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, hd[300005], f[300005], u[300005], v[300005], in[300005];
bool vis[300005];
struct node {
  int to, next;
} e[300005];
int read() {
  int f = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    f = f * 10 + ch - '0';
    ch = getchar();
  }
  return f * w;
}
void addedge(int x, int y) {
  e[++cnt].next = hd[x];
  e[cnt].to = y;
  hd[x] = cnt;
  in[y]++;
}
void topo() {
  int tot = 0;
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (!in[i]) q.push(i), tot++;
  }
  while (!q.empty()) {
    int x = q.front(), num = q.size();
    q.pop();
    if (num == 1) {
      f[x] += n - tot;
    } else if (num == 2) {
      int flag = 0;
      int y = q.front();
      for (int i = hd[y]; i; i = e[i].next) {
        int to = e[i].to;
        if (in[to] == 1) {
          vis[x] = 1;
          flag = 1;
          break;
        }
      }
      if (!flag) f[x] += n - tot;
    }
    for (int i = hd[x]; i; i = e[i].next) {
      int to = e[i].to;
      in[to]--;
      if (!in[to]) q.push(to), tot++;
    }
  }
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    u[i] = read(), v[i] = read();
    addedge(u[i], v[i]);
  }
  topo();
  memset(in, 0, sizeof(in));
  memset(hd, 0, sizeof(hd));
  cnt = 0;
  for (int i = 1; i <= m; i++) {
    addedge(v[i], u[i]);
  }
  topo();
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i] && f[i] >= n - 2) ans++;
  }
  cout << ans << endl;
  return 0;
}
