#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> e[300010];
vector<int> rev[300010];
int deg[300010];
int cnt[300010];
void add(int u, int x) {
  for (int i = 0; i < rev[u].size(); i++) cnt[rev[u][i]] += x;
  return;
}
queue<int> q;
void work(int u) {
  deg[u]--;
  if (!deg[u]) {
    add(u, -1);
    q.push(u);
  } else if (deg[u] == 1)
    add(u, 1);
  return;
}
int check() {
  if (!q.size()) return 0;
  if (q.size() > 1) return 2;
  int u = q.front();
  if (cnt[u]) return 2;
  return 1;
}
void solve(int* ans) {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) deg[i] = rev[i].size();
  for (int i = 1; i <= n; i++)
    if (!deg[i])
      q.push(i);
    else if (deg[i] == 1)
      add(i, 1);
  for (int i = 1; i <= n; i++) {
    int u = q.front();
    q.pop();
    int x = check();
    if (x == 2)
      ans[u] = -1;
    else
      ans[u] = n - i - x;
    for (int j = 0; j < e[u].size(); j++) {
      int v = e[u][j];
      work(v);
    }
  }
  return;
}
int a[300010];
int b[300010];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    e[u].push_back(v);
    rev[v].push_back(u);
  }
  solve(a);
  for (int i = 1; i <= n; i++) swap(e[i], rev[i]);
  solve(b);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] + b[i] >= n - 2) ans++;
  printf("%d\n", ans);
  return 0;
}
