#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int N, M, s;
vector<bool> ok(5010, false);
vector<vector<int>> G(5010);
void dfs(int v) {
  ok[v] = true;
  for (int nv : G[v]) {
    if (ok[nv]) continue;
    dfs(nv);
  }
}
vector<bool> used(5010, false);
int cnt = 0;
void dfs2(int v) {
  used[v] = true;
  cnt++;
  for (int nv : G[v]) {
    if (!used[nv] and !ok[nv]) {
      dfs2(nv);
    }
  }
}
int main() {
  cin >> N >> M >> s;
  s--;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
  }
  dfs(s);
  vector<P> rem;
  for (int i = 0; i < N; i++) {
    if (ok[i]) continue;
    used.assign(N, false);
    cnt = 0;
    dfs2(i);
    rem.emplace_back(cnt, i);
  }
  sort(rem.begin(), rem.end(), greater<P>());
  int ans = 0;
  for (int i = 0; i < rem.size(); i++) {
    if (ok[rem[i].second]) continue;
    ans++;
    dfs(rem[i].second);
  }
  cout << ans << '\n';
  ;
  return 0;
}
