#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
  register T f = 1;
  register char ch = getchar();
  t = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
  t *= f;
  return t;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
const long long p = 998244353;
inline long long power(register long long x, register long long k = p - 2) {
  register long long re = 1;
  for (; k; k >>= 1, x = x * x % p)
    if (k & 1) re = re * x % p;
  return re;
}
int n, m;
int head[300005], ne[300005], to[3000005], total = 1;
int deg[300005];
inline void add(int a, int b) {
  deg[b]++;
  total++;
  to[total] = b;
  ne[total] = head[a];
  head[a] = total;
}
int X[300005], Y[300005];
int f[300005];
void solve() {
  memset(head, 0, sizeof(head));
  total = 1;
  for (int i = 1; i <= m; i++) add(X[i], Y[i]);
  queue<int> q;
  int res = n;
  for (int i = 1; i <= n; i++)
    if (deg[i] == 0) q.push(i), res--;
  while (q.size()) {
    int now = q.front();
    q.pop();
    if (q.size() == 0) f[now] += res;
    if (q.size() > 1) f[now] = -1e9;
    if (q.size() == 1) {
      f[now] += res;
      int qwq = q.front();
      for (int i = head[qwq]; i; i = ne[i])
        if (deg[to[i]] == 1) f[now] = -1e9;
    }
    for (int i = head[now]; i; i = ne[i]) {
      deg[to[i]]--;
      if (deg[to[i]] == 0) q.push(to[i]), res--;
    }
  }
}
int main() {
  read(n, m);
  for (int i = 1; i <= m; i++) read(X[i], Y[i]);
  solve();
  for (int i = 1; i <= m; i++) swap(X[i], Y[i]);
  solve();
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (f[i] + 1 >= n - 1) ans++;
  printf("%d\n", ans);
  return 0;
}
