#include <bits/stdc++.h>
const int max_N = 302401;
int n, m, ans, num[max_N], deg[max_N];
std::vector<std::vector<int> > G[2];
std::queue<int> Q;
int read() {
  char c = getchar();
  int ans = 0;
  bool flag = true;
  while (!isdigit(c)) flag &= (c != '-'), c = getchar();
  while (isdigit(c)) ans = ans * 10 + c - '0', c = getchar();
  return flag ? ans : -ans;
}
void Write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + '0');
  else
    Write(x / 10), putchar(x % 10 + '0');
}
int min(int x, int y) { return x < y ? x : y; }
int max(int x, int y) { return x > y ? x : y; }
void _min(int &x, int y) {
  if (x > y) x = y;
}
void _max(int &x, int y) {
  if (x < y) x = y;
}
void solve(std::vector<std::vector<int> > G) {
  std::fill(deg + 1, deg + n + 1, 0);
  for (int i = 1; i <= n; i++)
    for (auto j : G[i]) ++deg[j];
  for (int i = 1; i <= n; i++)
    if (!deg[i]) Q.push(i);
  for (int i = 1; i <= n; i++) {
    int cur = Q.front();
    Q.pop();
    if (Q.empty()) num[cur] += n - i;
    if (Q.size() == 1) {
      bool flag = true;
      for (auto j : G[Q.front()]) flag &= (deg[j] > 1);
      if (flag) num[cur] += n - i - 1;
    }
    for (auto j : G[cur])
      if (!--deg[j]) Q.push(j);
  }
}
int main() {
  n = read(), m = read();
  G[0].resize(n + 1), G[1].resize(n + 1);
  for (int i = 1, u, v; i <= m; i++)
    u = read(), v = read(), G[0][u].push_back(v), G[1][v].push_back(u);
  solve(G[0]), solve(G[1]);
  for (int i = 1; i <= n; i++) ans += (num[i] >= n - 2);
  return Write(ans), 0;
}
