#include <bits/stdc++.h>
using namespace std;
int n, m, res;
vector<int> nodes, mid, hid;
vector<vector<int> > edges, anti;
void toposort() {
  vector<int> cnt(n);
  for (int i = 0; i < (int)edges.size(); i++) {
    for (auto j : edges[i]) cnt[j]++;
  }
  deque<int> sink;
  for (int i = 0; i < n; i++) {
    if (cnt[i] == 0) sink.push_back(i);
  }
  while (sink.size()) {
    if (!sink.size()) break;
    int v = sink.front();
    sink.pop_front();
    for (auto i : edges[v]) {
      cnt[i]--;
      if (cnt[i] == 0) sink.push_back(i);
    }
    nodes.push_back(v);
  }
}
vector<int> bach() {
  vector<int> cnt(n), res(n);
  vector<vector<int> > follow(n);
  unordered_set<int> sink, lv2;
  for (int i = 0; i < (int)nodes.size(); i++) {
    sink.insert(nodes[i]);
    for (auto u : anti[nodes[i]]) {
      cnt[u]++;
      if (lv2.find(u) != lv2.end()) lv2.erase(u);
      if (cnt[u] > 1) continue;
      for (auto j : follow[u]) lv2.erase(j);
      sink.erase(u);
      follow[nodes[i]].push_back(u);
      lv2.insert(u);
    }
    if (sink.size() == 1)
      res[nodes[i]] = 2;
    else {
      if (sink.size() == 2) {
        if (lv2.size() == follow[nodes[i]].size()) res[nodes[i]] = 1;
      }
    }
  }
  return res;
}
vector<int> forth() {
  vector<int> cnt(n), res(n);
  vector<vector<int> > follow(n);
  unordered_set<int> sink, lv2;
  for (int i = nodes.size() - 1; i >= 0; i--) {
    sink.insert(nodes[i]);
    for (auto u : edges[nodes[i]]) {
      cnt[u]++;
      if (lv2.find(u) != lv2.end()) lv2.erase(u);
      if (cnt[u] > 1) continue;
      for (auto j : follow[u]) lv2.erase(j);
      sink.erase(u);
      follow[nodes[i]].push_back(u);
      lv2.insert(u);
    }
    if (sink.size() == 1)
      res[nodes[i]] = 2;
    else {
      if (sink.size() == 2) {
        if (lv2.size() == follow[nodes[i]].size()) res[nodes[i]] = 1;
      }
    }
  }
  return res;
}
int main() {
  scanf("%d %d", &n, &m);
  edges.resize(n);
  anti.resize(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    edges[u].push_back(v);
    anti[v].push_back(u);
  }
  toposort();
  mid = bach();
  hid = forth();
  for (int i = 0; i < n; i++) {
    if (mid[i] + hid[i] > 2) res++;
  }
  printf("%d", res);
  return 0;
}
