#include <bits/stdc++.h>
using namespace std;
vector<int> mp[2][300005];
int d[2][300005];
queue<int> q;
int n, m, u, v, ans;
int cnt[300005];
void solve(int p) {
  int tot, x, y;
  bool f;
  tot = n;
  for (int i = 1; i <= n; i++)
    if (d[p][i] == 0) {
      q.push(i);
      tot--;
    }
  while (!q.empty()) {
    x = q.front();
    q.pop();
    if (q.empty())
      cnt[x] += tot;
    else if (q.size() == 1) {
      y = q.front();
      f = true;
      for (int i = 0; i < mp[p][y].size(); i++)
        if (d[p][mp[p][y][i]] <= 1) {
          f = false;
          break;
        }
      if (f) cnt[x] += tot;
    }
    for (int i = 0; i < mp[p][x].size(); i++) {
      d[p][mp[p][x][i]]--;
      if (d[p][mp[p][x][i]] == 0) {
        q.push(mp[p][x][i]);
        tot--;
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    mp[0][u].push_back(v);
    d[0][v]++;
    mp[1][v].push_back(u);
    d[1][u]++;
  }
  solve(0);
  solve(1);
  for (int i = 1; i <= n; i++)
    if (cnt[i] + 2 >= n) ans++;
  printf("%d\n", ans);
  return 0;
}
