#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
int ru[300010][2], sum[300010], head[300010];
vector<int> edge[300010][2];
inline void topo_sort(int op) {
  queue<int> q;
  int cnt = n;
  for (int i = 1; i <= n; i++)
    if (ru[i][op] == 0) q.push(i), cnt--;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    if (q.empty())
      sum[u] += cnt;
    else if (q.size() == 1) {
      int v = q.front();
      int flag = true;
      for (int i = 0; i < edge[v][op].size(); i++) {
        if (ru[edge[v][op][i]][op] == 1) flag = false;
      }
      if (flag == true) sum[u] += cnt;
    }
    for (int i = 0; i < edge[u][op].size(); i++) {
      int now = edge[u][op][i];
      ru[now][op]--;
      if (ru[now][op] == 0) q.push(now), cnt--;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u][0].push_back(v);
    edge[v][1].push_back(u);
    ru[v][0]++, ru[u][1]++;
  }
  topo_sort(0);
  topo_sort(1);
  for (int i = 1; i <= n; i++)
    if (sum[i] >= n - 2) ans++;
  printf("%d\n", ans);
  return 0;
}
