#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 300010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b, ans;
int P[MAXN];
bool mark[MAXN];
int L[MAXN], R[MAXN];
long long ps1[MAXN], ps2[MAXN];
vector<int> topol, G[MAXN], GR[MAXN];
void dfs(int node) {
  mark[node] = 1;
  for (int v : G[node])
    if (!mark[v]) dfs(v);
  topol.push_back(node);
}
bool cmp(int x, int y) { return P[x] < P[y]; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  while (m--) {
    cin >> u >> v;
    G[u].push_back(v);
    GR[v].push_back(u);
  }
  for (int i = 1; i <= n; i++)
    if (!mark[i]) dfs(i);
  topol.push_back(0);
  reverse(topol.begin(), topol.end());
  for (int i = 1; i <= n; i++) P[topol[i]] = i, R[i] = n + 1;
  for (int v = 1; v <= n; v++) {
    sort(G[v].begin(), G[v].end(), cmp);
    sort(GR[v].begin(), GR[v].end(), cmp);
    int l = 0, r = n + 1;
    if (GR[v].size()) l = P[GR[v].back()];
    if (G[v].size()) r = P[G[v][0]];
    ps1[l + 1]++;
    ps1[r]--;
    ps2[l + 1] += v;
    ps2[r] -= v;
    if (G[v].size()) {
      int tmp = n + 1;
      if (G[v].size() > 1) tmp = P[G[v][1]];
      L[G[v][0]] = max(L[G[v][0]], tmp);
    }
    if (GR[v].size()) {
      int tmp = 0;
      if (GR[v].size() > 1) tmp = P[GR[v][GR[v].size() - 2]];
      R[GR[v].back()] = min(R[GR[v].back()], tmp);
    }
  }
  for (int i = 1; i <= n; i++) ps1[i] += ps1[i - 1], ps2[i] += ps2[i - 1];
  for (int v = 1; v <= n; v++) ps1[v]--, ps2[P[v]] -= v;
  for (int v = 1; v <= n; v++)
    if (ps1[P[v]] <= 1) {
      if (!ps1[P[v]]) {
        ans++;
        continue;
      }
      int bad = ps2[P[v]];
      if (P[bad] < P[v]) {
        if (L[bad] <= P[v]) ans++;
        continue;
      }
      if (P[v] <= R[bad]) ans++;
      continue;
    }
  cout << ans << '\n';
  return 0;
}
