#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  bool f = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  x = f ? -x : x;
}
const int N = 3e5 + 7;
int n, m;
int a[N];
struct Graph {
  int head[N], to[N], nxt[N], tot;
  int in[N], f[N];
  bool vis[N];
  void adde(int u, int v) {
    to[++tot] = v;
    nxt[tot] = head[u];
    head[u] = tot;
  }
  void solve(int x, int y, int res) {
    for (int i = head[y], v = to[i]; i; i = nxt[i], v = to[i]) {
      if (in[v] == 1) {
        vis[x] = true;
        break;
      }
    }
    if (!vis[x]) {
      f[x] += res - 1;
    }
  }
  void topu() {
    queue<int> q;
    int res = n;
    for (int i = (1), _ = (n); i <= _; ++i)
      if (!in[i]) q.push(i);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      --res;
      if (q.empty())
        f[u] += res;
      else if (q.size() == 1)
        solve(u, q.front(), res);
      for (int i = head[u], v = to[i]; i; i = nxt[i], v = to[i]) {
        if (!(--in[v])) q.push(v);
      }
    }
  }
} G, T;
signed main() {
  read(n);
  read(m);
  for (int i = (1), _ = (m); i <= _; ++i) {
    int x, y;
    read(x);
    read(y);
    G.adde(x, y);
    ++G.in[y];
    T.adde(y, x);
    ++T.in[x];
  }
  G.topu();
  T.topu();
  int ans = 0;
  for (int i = (1), _ = (n); i <= _; ++i)
    if ((!G.vis[i]) && (!T.vis[i]) && (G.f[i] + T.f[i] >= n - 2)) ++ans;
  printf("%d", ans);
  return 0;
}
