#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline bool Max(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool Min(T &a, T b) {
  return b < a ? a = b, 1 : 0;
}
const int N = 3e5 + 7;
int edc, n, m, sel;
int head[N], mark[N], u[N], v[N], ind[N], f[N], q[N], hd, tl;
struct edge {
  int lst, to;
  edge() {}
  edge(int lst, int to) : lst(lst), to(to) {}
} e[N * 2];
void Add(int a, int b) {
  e[++edc] = edge(head[a], b), head[a] = edc;
  ++ind[b];
}
void solve(int x, int y, int w) {
  bool fg = 0;
  for (int i = head[y], v = e[i].to; i; i = e[i].lst, v = e[i].to)
    if (ind[v] == 1) {
      fg = 1;
      break;
    }
  if (fg)
    mark[x] = 1;
  else
    f[x] += w;
}
void topo() {
  hd = 1, tl = 0;
  for (int i = 1; i <= n; ++i)
    if (!ind[i]) q[++tl] = i;
  for (; hd <= tl; ++hd) {
    int u = q[hd];
    if (hd == tl) f[u] += n - tl;
    if (tl - hd == 1) solve(q[tl - 1], q[tl], n - tl);
    for (int i = head[u], v = e[i].to; i; i = e[i].lst, v = e[i].to)
      if (--ind[v] == 0) q[++tl] = v;
  }
}
int main() {
  n = gi(), m = gi();
  for (int i = 1; i <= m; ++i) {
    u[i] = gi(), v[i] = gi();
    Add(u[i], v[i]);
  }
  topo();
  memset(ind, 0, sizeof ind);
  memset(head, 0, sizeof head);
  edc = 0;
  for (int i = 1; i <= m; ++i) Add(v[i], u[i]);
  topo();
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (!mark[i] && f[i] + 1 >= n - 1) ++ans;
  printf("%d\n", ans);
  return 0;
}
