#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, m, u[N], v[N], d[N], cnt[N];
vector<int> g[N];
void sol(int u[], int v[]) {
  for (int i = 0; i < n; i++) g[i].clear();
  for (int i = 0; i < m; i++) {
    g[u[i]].push_back(v[i]);
    d[v[i]]++;
  }
  queue<int> q;
  int tot = n;
  for (int i = 0; i < n; i++)
    if (!d[i]) q.push(i), tot--;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    if (q.empty())
      cnt[x] += tot;
    else if (q.size() == 1) {
      int c = 1;
      for (int i = 0, y = q.front(); i < g[y].size(); i++)
        c &= (d[g[y][i]] > 1);
      cnt[x] += tot * c;
    }
    for (int i = 0; i < g[x].size(); i++)
      if (!--d[g[x][i]]) {
        q.push(g[x][i]);
        tot--;
      }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u[i], &v[i]);
    --u[i], --v[i];
  }
  sol(u, v);
  sol(v, u);
  int ans = 0;
  for (int i = 0; i < n; i++) ans += (cnt[i] + 2 >= n);
  cout << ans << endl;
  return 0;
}
