#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 1;
struct Solver {
  int n, m, second, col[N];
  vector<int> gp[N];
  unordered_map<int, bool> vis, to;
  pair<int, int> dd[N];
  void read() {
    int l, r;
    cin >> n >> m >> second;
    for (int i = 0; i < m; i++) {
      cin >> l >> r;
      gp[l].push_back(r);
    }
    fill(col, col + n + 1, -1);
  }
  void solve() {
    int ans = 0, it = 0;
    for (int i = 1; i <= n; i++) {
      to[i] = true;
    }
    dfs(second, second);
    for (auto &e : to) {
      int cur = 0;
      dfs2(e.first, 0, cur, it);
      dd[it] = {cur, e.first};
      it++;
    }
    sort(dd, dd + it);
    for (int i = 0; i < it; i++) {
      if (vis[dd[it - 1 - i].second]) {
        continue;
      }
      dfs(dd[it - 1 - i].second, -1);
      ans++;
    }
    cout << ans;
  }
  void dfs(int v, int p) {
    vis[v] = true;
    to.erase(v);
    for (auto &t : gp[v]) {
      if (t == p) {
        continue;
      }
      if (!vis[t]) {
        dfs(t, v);
      }
    }
  }
  void dfs2(int v, int p, int &cnt, int it) {
    col[v] = it;
    cnt++;
    for (auto &t : gp[v]) {
      if (t == p) {
        continue;
      }
      if (col[t] != it) {
        dfs2(t, v, cnt, it);
      }
    }
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Solver sol;
  sol.read();
  sol.solve();
  return 0;
}
