#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 5;
pair<int, int> add[maxn];
vector<int> g[maxn];
int ans[4][maxn];
int in[maxn];
int vis[maxn];
int q[maxn];
int n, m;
void bfs(int id) {
  memset(q, 0, sizeof(q));
  memset(vis, 0, sizeof(vis));
  int l = 0, r = 0;
  for (int i = 1; i <= n; ++i)
    if (!in[i]) q[r++] = i;
  while (l < r) {
    int x = q[l++];
    if (l == r)
      ans[id][x] = n - r;
    else if (r - l == 1) {
      int now = q[l];
      int have = 0;
      for (auto &v : g[now]) {
        if (in[v] == 1) {
          ans[id][x] = -n;
          have = 1;
          break;
        }
      }
      if (!have) ans[id][x] = n - r;
    } else
      ans[id][x] = -n;
    for (auto &v : g[x]) {
      in[v]--;
      if (!in[v]) q[r++] = v;
    }
  }
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; ++i) g[i].clear();
    memset(in, 0, sizeof(in));
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < m; ++i) {
      scanf("%d%d", &add[i].first, &add[i].second);
      in[add[i].second]++;
      g[add[i].first].push_back(add[i].second);
    }
    bfs(0);
    memset(in, 0, sizeof(in));
    for (int i = 1; i <= n; ++i) g[i].clear();
    for (int i = 0; i < m; ++i) {
      in[add[i].first]++;
      g[add[i].second].push_back(add[i].first);
    }
    bfs(1);
    int da = 0;
    for (int i = 1; i <= n; ++i) {
      if (ans[0][i] + ans[1][i] >= n - 2) da++;
    }
    printf("%d\n", da);
  }
}
