#include <bits/stdc++.h>
using namespace std;
int rd() {
  char c = getchar();
  int t = 0, f = 1;
  while (!isdigit(c)) f = (c == '-') ? -1 : 1, c = getchar();
  while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
  return t * f;
}
void wt(int x) {
  if (x < 0)
    putchar('-'), wt(-x);
  else {
    if (x > 9) wt(x / 10);
    putchar(x % 10 + 48);
  }
}
const int N = 3e5 + 35;
vector<int> A[N], B[N];
int n, m, in[N], out[N], que[N], len, top, stk[N], vis[N], L[N], R[N], ans,
    key[N], ok[N], inq[N], q[N];
void getque() {
  static int x, y, h, t, id, Q[N], f[N], p[N];
  for (int i = ((int)1); i <= ((int)n); i++)
    if (!in[i]) Q[++t] = i;
  while (h < t) {
    x = Q[++h];
    for (int j = ((int)0); j <= ((int)A[x].size() - 1); j++) {
      y = A[x][j];
      if (!--in[y]) Q[++t] = y, p[y] = x, f[y] = f[x] + 1;
    }
  }
  for (int i = ((int)1); i <= ((int)n); i++)
    if (f[i] > f[id]) id = i;
  que[++len] = id;
  while (p[id]) id = p[id], que[++len] = id;
  for (int i = ((int)1); i <= ((int)len); i++) inq[que[i]] = 1;
  reverse(que + 1, que + len + 1);
  return;
}
void dfs(int x, vector<int> A[], int &key) {
  stk[++top] = x;
  vis[x] = 1, key++;
  for (int j = ((int)0); j <= ((int)A[x].size() - 1); j++) {
    int y = A[x][j];
    if (!vis[y]) dfs(y, A, key);
  }
}
void solve(vector<int> A[], vector<int> B[], int out[], int R[]) {
  int x, y;
  memset(vis, 0, sizeof vis);
  for (int i = ((int)1); i <= ((int)n); i++)
    if (ok[i] && !A[i].size()) out[i] = 1;
  for (int i = ((int)len); i >= ((int)1); i--) {
    x = que[i];
    dfs(x, A, out[x]);
    out[x] += out[que[i + 1]], top = 0;
    for (int j = ((int)0); j <= ((int)B[x].size() - 1); j++) {
      y = B[x][j];
      if (!ok[y] || inq[y] || x != q[R[y]]) continue;
      dfs(y, A, out[y]), out[y] += out[x];
      while (top) vis[stk[top--]] = 0;
    }
  }
}
int main() {
  n = rd(), m = rd();
  for (int i = ((int)1); i <= ((int)m); i++) {
    int x = rd(), y = rd();
    A[x].push_back(y), B[y].push_back(x), in[y]++;
  }
  getque();
  for (int i = ((int)1); i <= ((int)n); i++) L[i] = 0, R[i] = len + 1;
  for (int i = ((int)len); i >= ((int)1); i--)
    for (int j = ((int)0); j <= ((int)A[que[i]].size() - 1); j++)
      if (!inq[A[que[i]][j]] && !L[A[que[i]][j]]) L[A[que[i]][j]] = i;
  for (int i = ((int)1); i <= ((int)len); i++)
    for (int j = ((int)0); j <= ((int)B[que[i]].size() - 1); j++)
      if (!inq[B[que[i]][j]] && R[B[que[i]][j]] == len + 1) R[B[que[i]][j]] = i;
  for (int i = ((int)1); i <= ((int)n); i++)
    if (L[i] + 1 == R[i] - 1) key[L[i]]++;
  for (int i = ((int)1); i <= ((int)n); i++)
    if (L[i] + 1 == R[i] - 1 && key[L[i]] == 1) ok[i] = 1;
  for (int i = ((int)1); i <= ((int)n); i++) q[i] = que[i];
  solve(A, B, out, R);
  reverse(que + 1, que + len + 1);
  solve(B, A, in, L);
  for (int i = ((int)1); i <= ((int)n); i++)
    if (in[i] + out[i] - 1 >= n - 1) ans++;
  printf("%d\n", ans);
  return 0;
}
