#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 5;
vector<int> adj[MAX], rvr[MAX];
int wasted[MAX], in[MAX], out[MAX], single_into[MAX], into_who[MAX];
int n, m;
vector<int> topo_sort() {
  vector<int> t;
  queue<int> q;
  for (int i = int(1); i < int(n + 1); i++) {
    if (in[i] == 0) {
      q.push(i);
    }
  }
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    t.push_back(cur);
    for (auto &each : adj[cur]) {
      in[each]--;
      if (in[each] == 0) {
        q.push(each);
      }
    }
  }
  return t;
}
void roll(const vector<int> &t, vector<int> graph[MAX]) {
  memset(out, 0, sizeof out);
  memset(single_into, 0, sizeof single_into);
  memset(into_who, 0, sizeof into_who);
  int single_set = 0;
  int in_set = 0;
  for (auto &each : t) {
    for (auto &inputter : graph[each]) {
      if (out[inputter] == 0) {
        in_set--;
        single_set ^= inputter;
        single_into[each]++;
        into_who[inputter] = each;
      } else if (out[inputter] == 1) {
        single_into[into_who[inputter]]--;
      }
      out[inputter]++;
    }
    if (in_set == 1) {
      int wolf = single_set;
      wasted[each] += single_into[wolf] + 1;
    } else if (in_set > 1) {
      wasted[each] += 2;
    }
    in_set++;
    single_set ^= each;
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = int(0); i < int(m); i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    rvr[v].push_back(u);
    in[v]++;
  }
  vector<int> t = topo_sort();
  roll(t, rvr);
  reverse(t.begin(), t.end());
  roll(t, adj);
  int ans = 0;
  for (int i = int(1); i < int(n + 1); i++) {
    ans += wasted[i] <= 1;
  }
  printf("%d\n", ans);
  return 0;
}
