#include <bits/stdc++.h>
using namespace std;
vector<bool> mark;
bool used[5010];
vector<vector<int>> adjacenciesOf;
void dfs(int v) {
  stack<int> s;
  s.push(v);
  while (!s.empty()) {
    int vertex = s.top();
    s.pop();
    mark[vertex] = true;
    for (int adj : adjacenciesOf[vertex]) {
      if (!mark[adj]) s.push(adj);
    }
  }
}
int dfs1(int v) {
  int cnt = 0;
  stack<int> s;
  s.push(v);
  while (!s.empty()) {
    int vertex = s.top();
    s.pop();
    used[vertex] = true;
    ++cnt;
    for (int adj : adjacenciesOf[vertex]) {
      if (!used[adj] && !mark[adj]) s.push(adj);
    }
  }
  return cnt;
}
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  mark.resize(n + 1, false);
  adjacenciesOf.resize(n + 1);
  while (m--) {
    int a, b;
    cin >> a >> b;
    adjacenciesOf[a].push_back(b);
  }
  dfs(s);
  vector<pair<int, int>> val;
  for (int i = 1; i <= n; ++i) {
    if (!mark[i]) {
      memset(used, false, sizeof(used));
      val.emplace_back(make_pair(dfs1(i), i));
    }
  }
  sort(val.begin(), val.end());
  reverse(val.begin(), val.end());
  int ans = 0;
  for (pair<int, int> it : val) {
    if (!mark[it.second]) {
      ++ans;
      dfs(it.second);
    }
  }
  cout << ans << endl;
  return 0;
}
