#include <bits/stdc++.h>
using namespace std;
queue<pair<int, int> > q;
int n, m;
vector<int> AdjList[300001], re[300001];
int deg[300001];
int f[300001], p[300001];
int in[300001], out[300001];
int L[300001], R[300001], id[300011];
bool vis[300001], on_P[300001];
vector<int> P, S;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    AdjList[u].push_back(v);
    re[v].push_back(u);
    deg[v]++;
  }
  for (int i = 1; i <= n; i++)
    if (!deg[i]) {
      q.push(pair<int, int>(i, 1));
      f[i] = 1;
    }
  while (!q.empty()) {
    int u = q.front().first;
    int x = q.front().second;
    q.pop();
    for (int i = 0; i < AdjList[u].size(); i++) {
      int v = AdjList[u][i];
      deg[v]--;
      if (x + 1 > f[v]) {
        f[v] = x + 1;
        p[v] = u;
      }
      if (!deg[v]) q.push(pair<int, int>(v, f[v]));
    }
  }
  int ed = -1, mx = 0;
  for (int i = 1; i <= n; i++)
    if (f[i] > mx) {
      ed = i;
      mx = f[i];
    }
  while (ed) {
    on_P[ed] = true;
    P.push_back(ed);
    ed = p[ed];
  }
  reverse(P.begin(), P.end());
  queue<int> cal_l, cal_r;
  for (int i = 1; i <= n; i++) {
    L[i] = P.size();
    R[i] = -1;
  }
  int pre = 0;
  for (int i = 1; i <= n; i++) vis[i] = false;
  for (int i = P.size() - 1; i >= 0; i--) {
    int st = P[i];
    cal_r.push(st);
    vis[st] = true;
    while (!cal_r.empty()) {
      int u = cal_r.front();
      cal_r.pop();
      out[st]++;
      for (int j = 0; j < AdjList[u].size(); j++) {
        int v = AdjList[u][j];
        if (!vis[v] && !on_P[v]) {
          vis[v] = true;
          R[v] = i;
          cal_r.push(v);
        }
      }
    }
    out[st] += out[pre];
    pre = st;
  }
  pre = 0;
  for (int i = 1; i <= n; i++) vis[i] = false;
  for (int i = 0; i < P.size(); i++) {
    int st = P[i];
    cal_l.push(st);
    vis[st] = true;
    while (!cal_l.empty()) {
      int u = cal_l.front();
      cal_l.pop();
      in[st]++;
      for (int j = 0; j < re[u].size(); j++) {
        int v = re[u][j];
        if (!vis[v] && !on_P[v]) {
          vis[v] = true;
          L[v] = i;
          cal_l.push(v);
        }
      }
    }
    in[st] += in[pre];
    pre = st;
  }
  for (int i = 1; i <= n; i++)
    if (!on_P[i] && (L[i] - 2 == R[i])) {
      if (id[L[i]])
        id[L[i]] = -1;
      else if (!id[L[i]])
        id[L[i]] = i;
    }
  for (int i = 1; i <= n; i++)
    if (!on_P[i]) in[i] = out[i] = 1;
  queue<int> CurrList;
  for (int i = 1; i <= n; i++) vis[i] = false;
  for (int i = P.size() - 1; i >= 0; i--) {
    int u = P[i];
    CurrList.push(u);
    vis[u] = true;
    while (!CurrList.empty()) {
      int cur = CurrList.front();
      CurrList.pop();
      for (int j = 0; j < AdjList[cur].size(); j++) {
        int v = AdjList[cur][j];
        if (!on_P[v] && !vis[v]) {
          vis[v] = true;
          CurrList.push(v);
        }
      }
    }
    if (id[i] >= 1) {
      out[id[i]] += out[u];
      CurrList.push(id[i]);
      vector<int> tmp;
      vis[id[i]] = true;
      while (!CurrList.empty()) {
        int cur = CurrList.front();
        CurrList.pop();
        tmp.push_back(cur);
        for (int j = 0; j < AdjList[cur].size(); j++) {
          int v = AdjList[cur][j];
          if (!on_P[v] && !vis[v]) {
            vis[v] = true;
            out[id[i]]++;
            CurrList.push(v);
          }
        }
      }
      for (int i = 0; i < tmp.size(); i++) vis[tmp[i]] = false;
    }
  }
  for (int i = 1; i <= n; i++) vis[i] = false;
  for (int i = 0; i < P.size(); i++) {
    int u = P[i];
    CurrList.push(u);
    vis[u] = true;
    while (!CurrList.empty()) {
      int cur = CurrList.front();
      CurrList.pop();
      for (int j = 0; j < re[cur].size(); j++) {
        int v = re[cur][j];
        if (!on_P[v] && !vis[v]) {
          vis[v] = true;
          CurrList.push(v);
        }
      }
    }
    if (id[i + 2] >= 1) {
      in[id[i + 2]] += in[u];
      CurrList.push(id[i + 2]);
      vector<int> tmp;
      vis[id[i + 2]] = true;
      while (!CurrList.empty()) {
        int cur = CurrList.front();
        CurrList.pop();
        tmp.push_back(cur);
        for (int j = 0; j < re[cur].size(); j++) {
          int v = re[cur][j];
          if (!on_P[v] && !vis[v]) {
            vis[v] = true;
            in[id[i + 2]]++;
            CurrList.push(v);
          }
        }
      }
      for (int i = 0; i < tmp.size(); i++) vis[tmp[i]] = false;
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++)
    if ((in[i] + out[i] == n) || (in[i] + out[i] == n + 1)) res++;
  cout << res;
}
