#include <bits/stdc++.h>
const int N = 300005;
int n, m, f[N], in[N];
std::vector<int> e[N], g[N];
bool flag[N];
inline void add(int u, int v, std::vector<int> *e) {
  e[u].push_back(v), ++in[v];
}
void topu(std::vector<int> *e) {
  std::queue<int> q;
  int sum = 0;
  for (int i = 1; i <= n; ++i)
    if (!in[i]) q.push(i), ++sum;
  while (!q.empty()) {
    int u = q.front();
    if (q.size() == 1)
      f[u] += n - sum, q.pop();
    else if (q.size() == 2) {
      q.pop();
      bool cnt = false;
      for (std::vector<int>::iterator i = e[q.front()].begin();
           i != e[q.front()].end(); ++i)
        if (in[*i] == 1) cnt = true;
      if (cnt)
        flag[u] = true;
      else
        f[u] += n - sum;
    } else
      q.pop();
    for (std::vector<int>::iterator i = e[u].begin(); i != e[u].end(); ++i) {
      if (!(--in[*i])) q.push(*i), ++sum;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    add(u, v, e);
  }
  topu(e);
  memset(in, 0, sizeof(in));
  for (int i = 1; i <= n; ++i)
    for (std::vector<int>::iterator j = e[i].begin(); j != e[i].end(); ++j)
      add(*j, i, g);
  topu(g);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (f[i] == n - 1)
      ++ans;
    else if (f[i] == n - 2 && !flag[i])
      ++ans;
  }
  printf("%d", ans);
  return 0;
}
