#include <bits/stdc++.h>
using namespace std;
vector<int> G[300005], rG[300005], path;
int in[300005], out[300005], num[300005], tot[300005], bel[300005];
void solve(vector<int> H[]) {
  int cnt = 0, x = 0;
  memset(out, 0, sizeof(out));
  for (int i = 0; i < path.size(); i++) {
    int t = path[i];
    for (int j = 0; j < H[t].size(); j++) {
      int tt = H[t][j];
      if (out[tt] == 0) {
        cnt--;
        x ^= tt;
        bel[tt] = t;
        tot[t]++;
      } else if (out[tt] == 1) {
        tot[bel[tt]]--;
        bel[tt] = -1;
      }
      out[tt]++;
    }
    if (cnt == 1 && tot[x] == 0)
      num[t]++;
    else if (cnt != 0)
      num[t] += 2;
    cnt++;
    x ^= t;
  }
}
int main() {
  int n, m, u, v;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    in[v]++;
    rG[v].push_back(u);
  }
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    if (in[i] == 0) q.push(i);
  }
  while (!q.empty()) {
    int x = q.front();
    path.push_back(x);
    q.pop();
    for (int i = 0; i < G[x].size(); i++) {
      in[G[x][i]]--;
      if (in[G[x][i]] == 0) q.push(G[x][i]);
    }
  }
  solve(rG);
  reverse(path.begin(), path.end());
  solve(G);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (num[i] <= 1) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
