#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
vector<int> G1[maxn];
vector<int> G2[maxn];
int in1[maxn], in2[maxn];
int d[maxn];
int n, m, ans;
void tuopu1() {
  queue<int> que;
  int res = n;
  for (int i = 1; i <= n; i++) {
    if (in1[i] == 0) {
      que.push(i);
      res--;
    }
  }
  while (!que.empty()) {
    int t = que.front();
    que.pop();
    if (que.size() == 0) {
      d[t] += res;
    }
    if (que.size() == 1) {
      int flag = 1;
      int tt = que.front();
      for (int i = 0; i < G1[tt].size(); i++) {
        int c = G1[tt][i];
        if (in1[c] == 1) {
          flag = 0;
          break;
        }
      }
      if (flag == 1) d[t] += res;
    }
    for (int i = 0; i < G1[t].size(); i++) {
      int c = G1[t][i];
      if ((--in1[c]) == 0) {
        que.push(c);
        res--;
      }
    }
  }
}
void tuopu2() {
  queue<int> que;
  int res = n;
  for (int i = 1; i <= n; i++) {
    if (in2[i] == 0) {
      que.push(i);
      res--;
    }
  }
  while (!que.empty()) {
    int t = que.front();
    que.pop();
    if (que.size() == 0) {
      d[t] += res;
    }
    if (que.size() == 1) {
      int flag = 1;
      int tt = que.front();
      for (int i = 0; i < G2[tt].size(); i++) {
        int c = G2[tt][i];
        if (in2[c] == 1) {
          flag = 0;
          break;
        }
      }
      if (flag == 1) d[t] += res;
    }
    for (int i = 0; i < G2[t].size(); i++) {
      int c = G2[t][i];
      if ((--in2[c]) == 0) {
        que.push(c);
        res--;
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    G1[u].push_back(v);
    G2[v].push_back(u);
    in1[v]++;
    in2[u]++;
  }
  tuopu1();
  tuopu2();
  for (int i = 1; i <= n; i++) {
    if (d[i] >= n - 2) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
