#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 300000;
int n, m;
vector<int> out[MAXN];
vector<int> in[MAXN];
bool been[MAXN];
int top[MAXN], ntop;
int mxlen[MAXN], nxt[MAXN];
int path[MAXN], npath;
int pathidx[MAXN];
int q[MAXN], qhead, qtail;
int lidx[MAXN], ridx[MAXN];
int cand[MAXN];
int candidx[MAXN];
int numout[MAXN];
int numin[MAXN];
void dfstop(int at) {
  assert(!been[at]);
  been[at] = true;
  for (int i = (0); i < (((int)(out[at]).size())); ++i) {
    int to = out[at][i];
    if (!been[to]) dfstop(to);
  }
  top[ntop++] = at;
}
int solve() {
  ntop = 0;
  for (int i = (0); i < (n); ++i) been[i] = false;
  for (int i = (0); i < (n); ++i)
    if (!been[i]) dfstop(i);
  assert(ntop == n);
  reverse(top, top + ntop);
  for (int i = n - 1; i >= 0; --i) {
    int at = top[i];
    mxlen[at] = 1, nxt[at] = -1;
    for (int j = (0); j < (((int)(out[at]).size())); ++j) {
      int to = out[at][j];
      if (mxlen[to] + 1 > mxlen[at]) mxlen[at] = mxlen[to] + 1, nxt[at] = to;
    }
  }
  int mxgloblen = 0, fst = -1;
  for (int i = (0); i < (n); ++i)
    if (mxlen[i] > mxgloblen) mxgloblen = mxlen[i], fst = i;
  npath = 0;
  for (int at = fst; at != -1; at = nxt[at]) path[npath++] = at;
  for (int i = (0); i < (n); ++i) pathidx[i] = -1;
  for (int i = (0); i < (npath); ++i) pathidx[path[i]] = i;
  qhead = qtail = 0;
  for (int i = (0); i < (n); ++i) lidx[i] = -1;
  for (int i = npath - 1; i >= 0; --i) {
    q[qhead++] = path[i];
    while (qtail < qhead) {
      int at = q[qtail++];
      for (int j = (0); j < (((int)(out[at]).size())); ++j) {
        int to = out[at][j];
        if (pathidx[to] != -1 || lidx[to] != -1) continue;
        lidx[to] = i;
        q[qhead++] = to;
      }
    }
  }
  qhead = qtail = 0;
  for (int i = (0); i < (n); ++i) ridx[i] = -1;
  for (int i = (0); i < (npath); ++i) {
    q[qhead++] = path[i];
    while (qtail < qhead) {
      int at = q[qtail++];
      for (int j = (0); j < (((int)(in[at]).size())); ++j) {
        int to = in[at][j];
        if (pathidx[to] != -1 || ridx[to] != -1) continue;
        ridx[to] = i;
        q[qhead++] = to;
      }
    }
  }
  for (int i = (0); i < (npath); ++i) cand[i] = -1;
  for (int i = (0); i < (n); ++i)
    if (pathidx[i] == -1) {
      int opt = -1;
      if (lidx[i] == -1 && ridx[i] == 1) opt = 0;
      if (ridx[i] == -1 && lidx[i] == npath - 2) opt = npath - 1;
      if (lidx[i] != -1 && ridx[i] != -1 && lidx[i] + 2 == ridx[i])
        opt = lidx[i] + 1;
      if (opt == -1) continue;
      if (cand[opt] == -1)
        cand[opt] = i;
      else
        cand[opt] = -2;
    }
  for (int i = (0); i < (npath); ++i)
    if (cand[i] == -2) cand[i] = -1;
  for (int i = (0); i < (n); ++i) candidx[i] = -1;
  for (int i = (0); i < (npath); ++i)
    if (cand[i] != -1) candidx[cand[i]] = i;
  for (int i = (0); i < (n); ++i) numout[i] = numin[i] = -1;
  qhead = qtail = 0;
  for (int i = (0); i < (n); ++i) been[i] = false;
  for (int i = npath - 1; i >= 0; --i) {
    if (cand[i] != -1) {
      int qold = qhead;
      assert(!been[cand[i]]);
      been[cand[i]] = true;
      q[qhead++] = cand[i];
      while (qtail < qhead) {
        int at = q[qtail++];
        for (int j = (0); j < (((int)(out[at]).size())); ++j) {
          int to = out[at][j];
          if (been[to]) continue;
          been[to] = true;
          q[qhead++] = to;
        }
      }
      numout[cand[i]] = qhead;
      for (int j = (qold); j < (qhead); ++j) {
        int at = q[j];
        been[at] = false;
      }
      qtail = qhead = qold;
    }
    assert(!been[path[i]]);
    been[path[i]] = true;
    q[qhead++] = path[i];
    while (qtail < qhead) {
      int at = q[qtail++];
      for (int j = (0); j < (((int)(out[at]).size())); ++j) {
        int to = out[at][j];
        if (been[to]) continue;
        been[to] = true;
        q[qhead++] = to;
      }
    }
    numout[path[i]] = qhead;
  }
  qhead = qtail = 0;
  for (int i = (0); i < (n); ++i) been[i] = false;
  for (int i = (0); i < (npath); ++i) {
    if (cand[i] != -1) {
      int qold = qhead;
      assert(!been[cand[i]]);
      been[cand[i]] = true;
      q[qhead++] = cand[i];
      while (qtail < qhead) {
        int at = q[qtail++];
        for (int j = (0); j < (((int)(in[at]).size())); ++j) {
          int to = in[at][j];
          if (been[to]) continue;
          been[to] = true;
          q[qhead++] = to;
        }
      }
      numin[cand[i]] = qhead;
      for (int j = (qold); j < (qhead); ++j) {
        int at = q[j];
        been[at] = false;
      }
      qtail = qhead = qold;
    }
    assert(!been[path[i]]);
    been[path[i]] = true;
    q[qhead++] = path[i];
    while (qtail < qhead) {
      int at = q[qtail++];
      for (int j = (0); j < (((int)(in[at]).size())); ++j) {
        int to = in[at][j];
        if (been[to]) continue;
        been[to] = true;
        q[qhead++] = to;
      }
    }
    numin[path[i]] = qhead;
  }
  int ret = 0;
  for (int i = (0); i < (n); ++i)
    if ((pathidx[i] != -1 || candidx[i] != -1) && numin[i] + numout[i] >= n)
      ++ret;
  return ret;
}
void run() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    out[a].push_back(b);
    in[b].push_back(a);
  }
  printf("%d\n", solve());
}
int main() {
  run();
  return 0;
}
