#include <bits/stdc++.h>
using namespace std;
const int M = 5005;
int n, m, s, scc[M], ro[M], scc_cnt;
bool vis[M];
vector<int> vc[M];
vector<int> vd[M];
vector<int> ve[M];
vector<int> stk;
stack<int> S;
int low[M], now[M], dfs_cnt;
namespace doubleDFS {
void dfs1(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  for (auto v : vc[u]) dfs1(v);
  stk.push_back(u);
}
void dfs2(int u) {
  if (scc[u]) return;
  scc[u] = scc_cnt;
  for (auto v : vd[u]) dfs2(v);
}
void Scc() {
  memset(vis, 0, sizeof vis);
  memset(scc, 0, sizeof scc);
  scc_cnt = 0;
  stk.clear();
  for (int i = 1; i <= n; ++i) dfs1(i);
  for (int i = n - 1; i >= 0; --i) {
    int v = stk[i];
    if (scc[v] == 0) scc_cnt++, dfs2(v);
  }
}
}  // namespace doubleDFS
namespace Tarjan {
void dfs(int u) {
  now[u] = low[u] = ++dfs_cnt;
  S.push(u);
  for (auto v : vc[u]) {
    if (now[v] == 0) {
      dfs(v);
      low[u] = min(low[u], low[v]);
    } else if (scc[v] == 0)
      low[u] = min(low[u], now[v]);
  }
  if (now[u] == low[u]) {
    scc_cnt++;
    while (1) {
      int x = S.top();
      S.pop();
      scc[x] = scc_cnt;
      if (x == u) break;
    }
  }
}
void Scc() {
  memset(now, 0, sizeof now);
  memset(low, 0, sizeof low);
  scc_cnt = 0;
  dfs_cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (now[i] == 0) dfs(i);
}
}  // namespace Tarjan
int main() {
  scanf("%d%d%d", &n, &m, &s);
  int x, y;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &x, &y);
    vc[x].push_back(y);
    vd[y].push_back(x);
  }
  Tarjan::Scc();
  for (int u = 1; u <= n; ++u)
    for (auto v : vc[u])
      if (scc[u] != scc[v]) ve[scc[u]].push_back(scc[v]), ro[scc[v]]++;
  int ans = 0;
  for (int i = 1; i <= scc_cnt; ++i)
    if (i != scc[s]) ans += ro[i] == 0;
  printf("%d", ans);
}
