#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
} a[300001];
vector<int> g[300001];
int n, m, in[300001], can[300001], q[300001], f[300001];
void clear() {
  for (int i = 1; i <= n; i++) g[i].clear();
  memset(in, 0, sizeof(in));
}
void topsort() {
  int tot = 0, head = 1, tail = 0;
  for (int i = 1; i <= n; i++)
    if (!in[i]) q[++tail] = i, tot++;
  while (head <= tail) {
    if (tail - head + 1 == 1) f[q[head]] += n - tot;
    if (tail - head + 1 == 2) {
      for (int i = 0; i < g[q[tail]].size(); i++) {
        if (in[g[q[tail]][i]] == 1) {
          can[q[head]] = 1;
          break;
        }
      }
      if (!can[q[head]]) f[q[head]] += n - tot;
      for (int i = 0; i < g[q[head]].size(); i++) {
        if (in[g[q[head]][i]] == 1) {
          can[q[tail]] = 1;
          break;
        }
      }
    }
    for (int i = 0; i < g[q[head]].size(); i++) {
      in[g[q[head]][i]]--;
      if (!in[g[q[head]][i]]) q[++tail] = g[q[head]][i], tot++;
    }
    head++;
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> a[i].x >> a[i].y;
    g[a[i].x].push_back(a[i].y);
    in[a[i].y]++;
  }
  topsort();
  clear();
  for (int i = 1; i <= m; i++) g[a[i].y].push_back(a[i].x), in[a[i].x]++;
  topsort();
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (!can[i] && f[i] >= n - 2) cnt++;
  cout << cnt;
}
