#include <bits/stdc++.h>
using namespace std;
vector<int> vc[2][300002];
int root[300002], ans[300002];
int lefto[15000502], righto[15000502], cnt2[15000502], nw, rev[300002];
stack<int> st;
int upi(int node, int node2, int st, int en) {
  if (node == 0 || node2 == 0) return node ^ node2;
  if (cnt2[node] == en - st + 1) return node;
  if (cnt2[node2] == en - st + 1) return node2;
  int ps = ++nw;
  if (st == en) {
    assert(0 > 1);
    return ps;
  }
  int mid = (st + en) >> 1;
  lefto[ps] = upi(lefto[node], lefto[node2], st, mid);
  righto[ps] = upi(righto[node], righto[node2], mid + 1, en);
  cnt2[ps] = cnt2[lefto[ps]] + cnt2[righto[ps]];
  return ps;
}
int update(int node, int st, int en, int x) {
  if (st > x or en < x) return node;
  int ps = ++nw;
  if (st == en) {
    cnt2[ps] = 1;
    return ps;
  }
  int mid = (st + en) >> 1;
  if (mid >= x)
    lefto[ps] = update(0, st, mid, x);
  else
    righto[ps] = update(0, mid + 1, en, x);
  cnt2[ps] = cnt2[lefto[ps]] + cnt2[righto[ps]];
  return ps;
}
int n;
int cnt = 0;
void dfs(int v, int bol) {
  root[v] = 1;
  for (int i = 0; i < vc[bol][v].size(); i++) {
    int w = vc[bol][v][i];
    if (root[w]) continue;
    dfs(w, bol);
  }
  st.push(v);
}
void dfs2(int v, int bol) {
  root[v] = update(0, 1, n, rev[v]);
  for (int i = 0; i < vc[bol][v].size(); i++) {
    int w = vc[bol][v][i];
    if (root[w] == 0) dfs2(w, bol);
    root[v] = upi(root[v], root[w], 1, n);
  }
  ans[v] += cnt2[root[v]];
}
void run(int bol) {
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (root[i] == 0) dfs(i, bol);
  }
  for (int i = 1; i <= n; i++) root[i] = 0;
  vector<int> tp;
  while (st.size()) {
    int v = st.top();
    st.pop();
    rev[v] = ++cnt;
    tp.push_back(v);
  }
  for (int i = n - 1; i >= 0; i--) st.push(tp[i]);
  while (st.size()) {
    int v = st.top();
    st.pop();
    if (root[v]) continue;
    dfs2(v, bol);
  }
}
int main() {
  int i, j, k, l, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &l, &k);
    vc[0][l].push_back(k);
    vc[1][k].push_back(l);
  }
  run(0);
  for (int i = 1; i <= nw; i++) {
    cnt2[i] = 0;
    lefto[i] = 0;
    righto[i] = 0;
  }
  nw = 0;
  for (int i = 1; i <= n; i++) root[i] = 0;
  run(1);
  int out = 0;
  for (int i = 1; i <= n; i++) {
    if (ans[i] == n + 1 || ans[i] == n) out++;
  }
  cout << out << endl;
  return 0;
}
