#include <bits/stdc++.h>
using namespace std;
vector<int> g[10000];
int vis1[10000], vis2[10000];
int cnt;
void dfs(int node) {
  if (vis1[node]) return;
  vis1[node] = 1;
  for (auto i : g[node]) {
    if (vis1[i] == 0) dfs(i);
  }
}
void dfs1(int node) {
  if (vis2[node]) return;
  vis2[node] = 1;
  for (auto i : g[node]) {
    if (vis2[i] == 0) dfs1(i);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, c;
  cin >> n >> m >> c;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
  }
  dfs(c);
  vector<pair<int, int> > s;
  for (int i = 1; i <= n; i++) {
    cnt = 0;
    if (!vis1[i]) {
      memset(vis2, 0, sizeof(vis2));
      dfs1(i);
      for (int j = 1; j <= n; j++) {
        if (vis2[j] == 1 and vis1[j] == 0) cnt++;
      }
      s.push_back({cnt, i});
    }
  }
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  int ans = 0;
  for (auto i : s) {
    memset(vis2, 0, sizeof(vis2));
    cnt = 0;
    if (vis1[i.second] == 0) {
      dfs(i.second);
      ans++;
    }
  }
  cout << ans << endl;
  cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
       << '\n';
  return 0;
}
