#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline", "fast-math", "unroll-loops", \
                     "no-stack-protector")
using namespace std;
const int block_size = 320;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 7;
const long double eps = 1e-9;
const double PI = atan(1) * 4;
template <typename T>
inline int sign(const T &a) {
  if (a < 0) return -1;
  if (a > 0) return 1;
  return 0;
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline void in(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
long long twop(int x) { return 1LL << x; }
template <typename A, typename B>
inline void in(A &x, B &y) {
  in(x);
  in(y);
}
template <typename A, typename B, typename C>
inline void in(A &x, B &y, C &z) {
  in(x);
  in(y);
  in(z);
}
template <typename A, typename B, typename C, typename D>
inline void in(A &x, B &y, C &z, D &d) {
  in(x);
  in(y);
  in(z);
  in(d);
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
namespace SOLVE {
void main() {}
}  // namespace SOLVE
int n, m;
vector<int> G[300010], rG[300010];
pair<int, int> nxt[300010];
void getNxt(int cur) {
  if (nxt[cur].first) return;
  for (auto i : G[cur]) {
    getNxt(i);
    upmax(nxt[cur], make_pair(nxt[i].first + 1, i));
  }
}
int l[300010], r[300010];
bool inPath[300010];
vector<int> neighbor[300010];
vector<int> pathNodes;
void getInPath(int cur) {
  if (!cur) return;
  pathNodes.push_back(cur);
  inPath[cur] = 1;
  getInPath(nxt[cur].second);
}
namespace getL {
void dfs(int cur) {
  for (auto nxt : G[cur]) {
    if (!l[nxt]) {
      l[nxt] = l[cur];
      dfs(nxt);
    }
  }
}
void get() {
  for (long long i = ((int)pathNodes.size()) - 1; i >= 0; i--) {
    l[pathNodes[i]] = i + 1;
    dfs(pathNodes[i]);
  }
}
}  // namespace getL
namespace getR {
void dfs(int cur) {
  for (auto nxt : rG[cur]) {
    if (!r[nxt]) {
      r[nxt] = r[cur];
      dfs(nxt);
    }
  }
}
void get() {
  for (long long i = 0; i < ((int)pathNodes.size()); i++) {
    r[pathNodes[i]] = i + 1;
    dfs(pathNodes[i]);
  }
}
}  // namespace getR
void getNeighbor() {
  for (long long i = 1; i < n + 1; i++) {
    if (!inPath[i] && l[i] == r[i] - 2) {
      neighbor[l[i] + 1].push_back(i);
    }
  }
}
int reach[300010];
bool vis[300010];
namespace countNeighOut {
int cnt = 0;
void dfs(int cur) {
  if (vis[cur]) return;
  vis[cur] = 1;
  cnt++;
  for (auto nxt : G[cur]) {
    dfs(nxt);
  }
}
void solve() {
  memset(vis, 0, sizeof(vis));
  for (long long i = ((int)pathNodes.size()) - 1; i >= 0; i--) {
    if (((int)neighbor[i].size())) {
      dfs(neighbor[i][0]);
      reach[neighbor[i][0]] += cnt - 1;
    }
  }
}
}  // namespace countNeighOut
namespace countNeighIn {
int cnt = 0;
void dfs(int cur) {
  if (vis[cur]) return;
  vis[cur] = 1;
  cnt++;
  for (auto nxt : rG[cur]) {
    dfs(nxt);
  }
}
void solve() {
  memset(vis, 0, sizeof(vis));
  for (long long i = 0; i < ((int)pathNodes.size()); i++) {
    if (((int)neighbor[i].size())) {
      dfs(neighbor[i][0]);
      reach[neighbor[i][0]] += cnt;
    }
  }
}
}  // namespace countNeighIn
namespace countPathOut {
int cnt = 0;
void dfs(int cur) {
  if (vis[cur]) return;
  vis[cur] = 1;
  cnt++;
  for (auto nxt : G[cur]) {
    dfs(nxt);
  }
}
void solve() {
  memset(vis, 0, sizeof(vis));
  for (long long i = ((int)pathNodes.size()) - 1; i >= 0; i--) {
    dfs(pathNodes[i]);
    reach[pathNodes[i]] += cnt - 1;
  }
}
}  // namespace countPathOut
namespace countPathIn {
int cnt = 0;
void dfs(int cur) {
  if (vis[cur]) return;
  vis[cur] = 1;
  cnt++;
  for (auto nxt : rG[cur]) {
    dfs(nxt);
  }
}
void solve() {
  memset(vis, 0, sizeof(vis));
  for (long long i = 0; i < ((int)pathNodes.size()); i++) {
    dfs(pathNodes[i]);
    reach[pathNodes[i]] += cnt;
  }
}
}  // namespace countPathIn
int main() {
  in(n, m);
  for (long long i = 0; i < m; i++) {
    int u, v;
    in(u, v);
    v++;
    u++;
    G[u].push_back(v);
    rG[v].push_back(u);
  }
  n++;
  for (long long i = 2; i < n + 1; i++) {
    G[1].push_back(i);
    rG[i].push_back(1);
  }
  n++;
  for (long long i = 2; i < n; i++) {
    G[i].push_back(n);
    rG[n].push_back(i);
  }
  for (long long i = 1; i < n + 1; i++) sort(G[i].begin(), G[i].end());
  for (long long i = 1; i < n + 1; i++) sort(rG[i].begin(), rG[i].end());
  getNxt(1);
  getInPath(1);
  getL::get();
  getR::get();
  getNeighbor();
  for (long long i = 1; i < n + 1; i++) {
    if (((int)neighbor[i].size()) >= 2) {
      neighbor[i].clear();
    }
  }
  for (long long i = 1; i < n + 1; i++) {
    if (((int)neighbor[i].size()) && ((int)neighbor[i + 1].size())) {
      if (!binary_search(G[neighbor[i][0]].begin(), G[neighbor[i][0]].end(),
                         neighbor[i + 1][0])) {
        neighbor[i].clear();
      }
    }
  }
  for (long long i = n; i >= 1; i--) {
    if (((int)neighbor[i].size()) && ((int)neighbor[i - 1].size())) {
      if (!binary_search(rG[neighbor[i][0]].begin(), rG[neighbor[i][0]].end(),
                         neighbor[i - 1][0])) {
        neighbor[i].clear();
      }
    }
  }
  countPathIn::solve();
  countPathOut::solve();
  countNeighOut::solve();
  countNeighIn::solve();
  int ans = 0;
  for (long long i = 2; i < n; i++) {
    ans += reach[i] >= n - 1;
  }
  cout << ans << endl;
  return 0;
}
