#include <bits/stdc++.h>
using namespace std;
const int maxn = 300050, maxm = 500050;
int q[maxn], he, ta;
int head[maxn];
struct Edge {
  int next, to;
};
Edge ed[maxm];
int num_edge, indu[maxn];
void add_edge(int from, int to) {
  ed[++num_edge].next = head[from];
  ed[num_edge].to = to;
  head[from] = num_edge;
  indu[to]++;
}
void Clear() {
  memset(head, 0, sizeof(head));
  memset(ed, 0, sizeof(ed));
  num_edge = 0;
  memset(indu, 0, sizeof(indu));
}
bool can[maxn];
int n, m, f[maxn];
void topo() {
  int tot = 0;
  he = 1, ta = 0;
  for (int i = 1; i <= n; i++)
    if (indu[i] == 0) q[++ta] = i, tot++;
  while (he <= ta) {
    if (ta - he + 1 == 1) f[q[he]] += n - tot;
    if (ta - he + 1 == 2) {
      for (int i = head[q[ta]]; i; i = ed[i].next) {
        int to = ed[i].to;
        if (indu[to] == 1) {
          can[q[he]] = 0;
          break;
        }
      }
      if (can[q[he]] == 1) f[q[he]] += n - tot;
      for (int i = head[q[he]]; i; i = ed[i].next) {
        int to = ed[i].to;
        if (indu[to] == 1) {
          can[q[ta]] = 0;
          break;
        }
      }
    }
    for (int i = head[q[he]]; i; i = ed[i].next) {
      int to = ed[i].to;
      indu[to]--;
      if (indu[to] == 0) q[++ta] = to, tot++;
    }
    he++;
  }
}
int tmpv[maxn], tmpu[maxn];
int main() {
  memset(can, 1, sizeof(can));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &tmpv[i], &tmpu[i]);
    add_edge(tmpv[i], tmpu[i]);
  }
  topo();
  Clear();
  for (int i = 1; i <= m; i++) add_edge(tmpu[i], tmpv[i]);
  topo();
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (can[i] && f[i] >= n - 2) cnt++;
  printf("%d\n", cnt);
}
