#include <bits/stdc++.h>
using namespace std;
int gi() {
  int res = 0, w = 1;
  char ch = getchar();
  while (ch != '-' && !isdigit(ch)) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
  return res * w;
}
const int MAX_N = 3e5 + 5;
vector<int> G[MAX_N];
int N, M, eu[MAX_N], ev[MAX_N], deg[MAX_N];
int f[MAX_N];
void solve() {
  queue<int> que;
  int cnt = 0;
  for (int i = 1; i <= N; i++) G[i].clear(), deg[i] = 0;
  for (int i = 1; i <= M; i++) deg[ev[i]]++, G[eu[i]].push_back(ev[i]);
  for (int i = 1; i <= N; i++)
    if (!deg[i]) que.push(i);
  while (!que.empty()) {
    int x = que.front();
    que.pop(), ++cnt;
    if (!que.size())
      f[x] += N - cnt;
    else if (que.size() == 1) {
      int y = que.front();
      bool flag = 1;
      for (int v : G[y])
        if (deg[v] == 1) {
          flag = 0;
          break;
        }
      if (flag) f[x] += N - cnt - 1;
    }
    for (int v : G[x])
      if (!--deg[v]) que.push(v);
  }
}
int main() {
  N = gi(), M = gi();
  for (int i = 1; i <= M; i++) eu[i] = gi(), ev[i] = gi();
  solve();
  for (int i = 1; i <= M; i++) swap(eu[i], ev[i]);
  solve();
  int ans = 0;
  for (int i = 1; i <= N; i++) ans += f[i] >= N - 2;
  printf("%d\n", ans);
  return 0;
}
