#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, Q[N], in[N], out[N], num[N], cnt, m, id, to[N], key[N], ans;
void topsort() {
  static int x, h, t;
  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++) {
      int y = A[x][j];
      if (!--in[y]) Q[++t] = y;
    }
  }
  return;
}
void solve(vector<int> A[]) {
  id = cnt = 0;
  memset(num, 0, sizeof num);
  memset(out, 0, sizeof out);
  for (int i = ((int)1); i <= ((int)n); i++) {
    int x = Q[i];
    for (int j = ((int)0); j <= ((int)A[x].size() - 1); j++) {
      int y = A[x][j];
      if (!out[y]) {
        cnt--, id ^= y;
        num[to[y] = x]++;
      } else if (out[y] == 1) {
        num[to[y]]--;
        to[y] = -1;
      }
      out[y]++;
    }
    if (cnt == 1 && !num[id])
      key[x]++;
    else if (cnt > 0)
      key[x] += 2;
    cnt++, id ^= x;
  }
  return;
}
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]++;
  }
  topsort();
  solve(B);
  reverse(Q + 1, Q + n + 1);
  solve(A);
  for (int i = ((int)1); i <= ((int)n); i++)
    if (key[i] <= 1) ans++;
  printf("%d\n", ans);
  return 0;
}
