#include <bits/stdc++.h>
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;
using namespace std;
template <class TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char* sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
vector<long long> get_cnts(const vector<vector<long long> >& nei,
                           const vector<vector<long long> >& rev_nei,
                           long long n, vector<long long> ord) {
  vector<long long> cur_outdeg(n + 1, 0), preds(n + 1, 1), nxt(n + 1, 0),
      cnts(n + 1, 0), rnk(n + 1, n + 1);
  for (long long i = (long long)0; i < (long long)n; i++) {
    rnk[ord[i]] = i + 1;
  }
  for (long long v = (long long)1; v < (long long)n + 1; v++) {
    for (auto& w : nei[v]) {
      if (rnk[w] < rnk[nxt[v]]) {
        nxt[v] = w;
      }
    }
  }
  long long cur_cnt = 0;
  for (auto& v : ord) {
    for (auto& w : rev_nei[v]) {
      cur_outdeg[w]++;
      if (cur_outdeg[w] == 1) {
        cur_cnt -= preds[w];
        preds[v]++;
      } else if (cur_outdeg[w] == 2) {
        if (cur_outdeg[nxt[w]] == 0) {
          cur_cnt--;
          preds[nxt[w]]--;
        }
      }
    }
    cnts[v] = cur_cnt;
    cur_cnt += preds[v];
  }
  return cnts;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<vector<long long> > nei, rev_nei;
  long long n, m;
  cin >> n >> m;
  nei.resize(n + 1);
  rev_nei.resize(n + 1);
  vector<long long> indeg(n + 1, 0);
  for (long long _ = (long long)0; _ < (long long)m; _++) {
    long long u, v;
    cin >> u >> v;
    nei[u].push_back(v);
    rev_nei[v].push_back(u);
    indeg[v]++;
  }
  vector<long long> topo;
  for (long long v = (long long)1; v < (long long)n + 1; v++) {
    if (indeg[v] == 0) {
      topo.push_back(v);
    }
  }
  for (long long i = (long long)0; i < (long long)(long long)((topo).size());
       i++) {
    long long v = topo[i];
    if (0) cout << v << " ";
    for (auto& w : nei[v]) {
      indeg[w]--;
      if (indeg[w] == 0) {
        topo.push_back(w);
      }
    }
  }
  if (0) cout << endl;
  auto cnts_forward = get_cnts(nei, rev_nei, n, topo);
  reverse((topo).begin(), (topo).end());
  auto cnts_backward = get_cnts(rev_nei, nei, n, topo);
  long long res = 0;
  for (long long v = (long long)1; v < (long long)n + 1; v++) {
    (v, cnts_forward[v], cnts_backward[v]);
    if (cnts_forward[v] + cnts_backward[v] <= 1) {
      res++;
    }
  }
  cout << res << "\n";
  return 0;
}
