#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, m, ans[N], seq[N], tt, in[N], out[N], oid[N];
vector<int> E[N], rE[N];
void topsort(vector<int> *E) {
  static int deg[N];
  queue<int> q;
  for (int i = 1; i <= n; i++)
    for (auto j : E[i]) ++deg[j];
  for (int i = 1; i <= n; i++)
    if (!deg[i]) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    seq[++tt] = u;
    for (auto v : E[u])
      if (!--deg[v]) q.push(v);
  }
}
void solve(vector<int> *E) {
  int id = 0, cnt = 0;
  memset(in, 0, sizeof(in));
  memset(out, 0, sizeof(out));
  memset(oid, 0, sizeof(oid));
  for (int i = 1; i <= n; i++) {
    int u = seq[i];
    for (auto v : E[u]) {
      if (out[v] == 0) {
        --cnt;
        id ^= v;
        ++in[u];
        oid[v] = u;
      } else if (out[v] == 1) {
        --in[oid[v]];
      }
      ++out[v];
    }
    if (cnt == 1 && !in[id])
      ++ans[u];
    else if (cnt)
      ans[u] += 2;
    ++cnt;
    id ^= u;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1, u, v; i <= m; i++)
    u = gi(), v = gi(), E[u].push_back(v), rE[v].push_back(u);
  topsort(E);
  solve(rE);
  reverse(seq + 1, seq + n + 1);
  solve(E);
  int Ans = 0;
  for (int i = 1; i <= n; i++) {
    Ans += (ans[i] <= 1);
  }
  cout << Ans;
  return 0;
}
