#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  if (0) return;
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  if (0) return;
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
void get_it_done() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  if (a < b) return gcd(b, a);
  return gcd(b, a % b);
}
const long long N = 5e3 + 5;
long long n, m, s;
vector<long long> adjList[N];
bool visited[N], good[N];
long long cnt = 0;
void dfs1(long long src) {
  good[src] = 1;
  for (auto x : adjList[src]) {
    if (!good[x]) {
      dfs1(x);
    }
  }
}
void dfs2(long long src) {
  visited[src] = 1;
  cnt++;
  for (auto x : adjList[src]) {
    if (!visited[x] && !good[x]) {
      dfs2(x);
    }
  }
}
int32_t main() {
  get_it_done();
  long long tc = 1;
  while (tc--) {
    cin >> n >> m >> s;
    for (long long i = 0; i < m; ++i) {
      long long u, v;
      cin >> u >> v;
      adjList[u].push_back(v);
    }
    dfs1(s);
    vector<pair<long long, long long> > cntBad;
    for (long long i = 1; i < n + 1; ++i) {
      if (!good[i]) {
        memset(visited, 0, sizeof(visited));
        cnt = 0;
        dfs2(i);
        cntBad.push_back(make_pair(cnt, i));
      }
    }
    sort(cntBad.begin(), cntBad.end(), greater<pair<long long, long long> >());
    long long ans = 0;
    for (long long i = 0; i < cntBad.size(); ++i) {
      auto x = cntBad[i];
      if (!good[x.second]) {
        ans++;
        dfs1(x.second);
      }
    }
    cout << ans << "\n";
  }
}
