#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {}
int n, m;
int cnt[N];
int in[2][N];
vector<int> e[2][N];
int q[N], top;
void topsort(int p) {
  stack<int> s;
  top = 0;
  for (int i = 1; i <= n; ++i)
    if (!in[p][i]) q[top++] = i;
  for (int i = 0; i < top; ++i) {
    int u = q[i];
    if (top - i == 1)
      cnt[u] += n - top;
    else if (top - i == 2) {
      int flag = 0;
      int u2 = q[i + 1];
      for (auto v : e[p][u2])
        if (in[p][v] == 1) flag = 1;
      if (!flag) cnt[u] += n - top;
    }
    for (auto v : e[p][u])
      if ((--in[p][v]) == 0) q[top++] = v;
  }
}
inline void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[0][x].push_back(y), in[0][y]++;
    e[1][y].push_back(x), in[1][x]++;
  }
  topsort(0), topsort(1);
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans += (cnt[i] >= n - 2);
  cout << ans << endl;
}
int main() {
  TIME__START = clock();
  int Test = 1;
  while (Test--) {
    solve();
  }
  TIME__END = clock();
  program_end();
  return 0;
}
