#include <bits/stdc++.h>
using namespace std;
long long int n, m, s, cnt[5007];
bool g[5007], vis[5007];
vector<long long int> adj[5007];
void dfs(long long int x) {
  if (!g[x]) {
    cnt[x] = 1;
  }
  vis[x] = 1;
  for (long long int i : adj[x]) {
    if (!vis[i]) {
      dfs(i);
      cnt[x] += cnt[i];
    }
  }
}
void dfs2(long long int x) {
  g[x] = 1;
  vis[x] = 1;
  for (long long int i : adj[x]) {
    if (!vis[i]) {
      dfs2(i);
    }
  }
}
bool comp(long long int x, long long int y) { return cnt[x] > cnt[y]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> s;
  for (long long int i = 0; i < m; ++i) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
  }
  queue<long long int> ben;
  ben.push(s);
  while (!ben.empty()) {
    long long int f = ben.front();
    ben.pop();
    g[f] = 1;
    for (long long int i : adj[f]) {
      if (!g[i]) {
        g[i] = 1;
        ben.push(i);
      }
    }
  }
  vector<long long int> v;
  for (long long int i = 1; i <= n; ++i) {
    if (g[i]) continue;
    v.push_back(i);
    memset(vis, 0, sizeof(vis));
    dfs(i);
  }
  long long int ans = 0;
  sort(v.begin(), v.end(), comp);
  for (long long int i = 0; i < (long long int)v.size(); ++i) {
    if (g[v[i]]) continue;
    memset(vis, 0, sizeof(vis));
    dfs2(v[i]);
    ans++;
  }
  cout << ans << '\n';
  return 0;
}
