#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 69, MOD = 1e9 + 7;
long long n, m, src, ans, tag;
long long v[MAXN], u[MAXN], mark[MAXN], comp[MAXN], deg[MAXN];
vector<long long> topol, g[MAXN], revg[MAXN];
void dfs(long long v) {
  mark[v] = 1;
  for (auto u : g[v])
    if (!mark[u]) dfs(u);
  topol.push_back(v);
}
void kosaraju(long long v) {
  mark[v] = 1, comp[v] = tag;
  for (auto u : revg[v])
    if (!mark[u]) kosaraju(u);
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> src;
  for (long long i = 1; i <= m; i++)
    cin >> v[i] >> u[i], g[v[i]].push_back(u[i]), revg[u[i]].push_back(v[i]);
  for (long long i = 1; i <= n; i++)
    if (!mark[i]) dfs(i);
  memset(mark, 0, sizeof mark);
  reverse(topol.begin(), topol.end());
  for (auto it : topol)
    if (!mark[it]) tag++, kosaraju(it);
  for (long long i = 1; i <= m; i++)
    if (comp[v[i]] != comp[u[i]]) deg[comp[u[i]]]++;
  for (long long i = 1; i <= tag; i++)
    if (i != comp[src] and deg[i] == 0) ans++;
  cout << ans << "\n";
}
