#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v;
} e[300002];
int head[300002], ver[300002], nxt[300002], d[300002], l;
int n, m, i, ans[300002];
bool tag[300002];
int read() {
  char c = getchar();
  int w = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c <= '9' && c >= '0') {
    w = w * 10 + c - '0';
    c = getchar();
  }
  return w;
}
void insert(int x, int y) {
  l++;
  d[y]++;
  ver[l] = y;
  nxt[l] = head[x];
  head[x] = l;
}
void toposort() {
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (d[i] == 0) q.push(i);
  }
  int cnt = n;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    cnt--;
    if (q.size() == 0)
      ans[x] += cnt;
    else if (q.size() == 1) {
      int x1 = q.front(), flag = 1;
      for (int i = head[x1]; i; i = nxt[i]) {
        if (d[ver[i]] == 1) {
          flag = 0;
          break;
        }
      }
      if (flag) ans[x] += cnt - 1;
    }
    for (int i = head[x]; i; i = nxt[i]) {
      int y = ver[i];
      d[y]--;
      if (d[y] == 0) q.push(y);
    }
  }
}
int main() {
  n = read();
  m = read();
  for (i = 1; i <= m; i++) e[i].u = read(), e[i].v = read();
  for (i = 1; i <= m; i++) insert(e[i].u, e[i].v);
  toposort();
  memset(head, 0, sizeof(head));
  memset(d, 0, sizeof(d));
  l = 0;
  for (i = 1; i <= m; i++) insert(e[i].v, e[i].u);
  toposort();
  int res = 0;
  for (i = 1; i <= n; i++) {
    if (ans[i] >= n - 2) res++;
  }
  printf("%d\n", res);
  return 0;
}
