#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << ' ' << H;
  debug_out(T...);
}
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const int N = 5e5 + 5;
int n, m, M[N], D[N], C[N], P[N], R[N];
vector<int> G[2][N], T;
set<int> S;
void DFS(int v) {
  M[v] = true;
  for (int u : G[0][v])
    if (!M[u]) DFS(u);
  T.push_back(v);
}
void F(bool b) {
  memset(D, 0, sizeof D), memset(C, 0, sizeof C), memset(P, 0, sizeof P);
  S.clear();
  for (int v : T) {
    for (int u : G[b][v]) {
      D[u]++;
      if (D[u] == 1)
        S.erase(u), P[u] = v, C[v]++;
      else if (D[u] == 2)
        C[P[u]]--;
    }
    if ((int)(S.size()) == 1)
      R[v] += 1 + C[*S.begin()];
    else if ((int)(S.size()) > 1)
      R[v] += 2;
    S.insert(v);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  mt19937 Rnd(time(0));
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    G[0][v].push_back(u);
    G[1][u].push_back(v);
  }
  for (int i = 1; i <= n; i++)
    if (!M[i]) DFS(i);
  F(0), reverse(T.begin(), T.end()), F(1);
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += R[i] < 2;
  cout << ans << '\n';
  return 0;
}
