#include <bits/stdc++.h>
using namespace std;
const int limit = 1000000;
int amount[limit];
void insert(int pos, int a) {
  for (; pos; pos -= pos & -pos) amount[pos] += a;
}
int amountnext(int pos) {
  int s = 0;
  for (; pos < limit; pos += pos & -pos) s += amount[pos];
  return s;
}
void insertinv(int pos, int a) {
  for (; pos < limit; pos += pos & -pos) amount[pos] += a;
}
int amountinv(int pos) {
  int s = 0;
  for (; pos; pos -= pos & -pos) s += amount[pos];
  return s;
}
int n, m;
vector<int> g[limit];
vector<int> ginv[limit];
queue<int> q;
int arity[limit];
int arityinv[limit];
int nnode = 1;
int node[limit];
int position[limit];
int sol;
int desp[limit];
int init[limit];
int initinv[limit];
bool compare(int u, int v) { return position[u] < position[v]; }
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    ginv[v].push_back(u);
    arity[v]++;
    arityinv[u]++;
  }
  for (int u = 1; u <= n; u++) {
    if (arity[u] == 0) init[u] = 1;
    if (arityinv[u] == 0) initinv[u] = 1;
  }
  for (int u = 1; u <= n; u++) {
    if (arity[u] == 0) {
      q.push(u);
      position[u] = nnode;
      node[nnode++] = u;
    }
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vector<int> &ar = g[u];
    for (int i = 0; i < int(ar.size()); i++) {
      int v = ar[i];
      arity[v]--;
      if (arity[v] == 0) {
        q.push(v);
        position[v] = nnode;
        node[nnode++] = v;
      }
    }
  }
  for (int u = 1; u <= n; u++) {
    vector<int> &ar = g[u];
    sort(ar.begin(), ar.end(), compare);
    vector<int> &arinv = ginv[u];
    sort(arinv.begin(), arinv.end(), compare);
    reverse(arinv.begin(), arinv.end());
  }
  for (int i = 1; i <= n; i++) {
    int u = node[i];
    int add = amountnext(i);
    desp[u] += add;
    vector<int> &aru = g[u];
    if (int(aru.size()) == 0) {
      insert(n, 1);
      continue;
    }
    int ri = position[aru[0]];
    insert(ri - 1, 1);
    int v = node[ri];
    vector<int> &arv = g[v];
    if (int(arv.size()) == 0) {
      int RI = n + 1;
      if (1 < int(aru.size())) RI = position[aru[1]];
      insert(ri, -2);
      insert(RI - 1, 2);
      continue;
    }
    int RI = position[arv[0]];
    if (1 < int(aru.size())) RI = min(RI, position[aru[1]]);
    insert(ri, -2);
    insert(RI - 1, 2);
  }
  for (int i = 0; i < limit; i++) amount[i] = 0;
  for (int i = n; i >= 1; i--) {
    int u = node[i];
    int add = amountinv(i);
    desp[u] += add;
    vector<int> &aru = ginv[u];
    if (int(aru.size()) == 0) {
      insertinv(1, 1);
      continue;
    }
    int le = position[aru[0]];
    insertinv(le + 1, 1);
    int v = node[le];
    vector<int> &arv = ginv[v];
    if (int(arv.size()) == 0) {
      int LE = 0;
      if (1 < int(aru.size())) LE = position[aru[1]];
      insertinv(le, -2);
      insertinv(LE + 1, 2);
      continue;
    }
    int LE = position[arv[0]];
    if (1 < int(aru.size())) LE = max(LE, position[aru[1]]);
    insertinv(le, -2);
    insertinv(LE + 1, 2);
  }
  for (int u = 1; u <= n; u++) sol += desp[u] <= 1;
  cout << sol << endl;
}
