#include <bits/stdc++.h>
using namespace std;
bool vis[5010];
bool vis2[5010];
int cnt;
vector<vector<int>> graph(5010);
void dfs(int s) {
  vis[s] = true;
  vector<int> vizinho = graph[s];
  for (int i = 0; i < vizinho.size(); ++i) {
    if (!vis[vizinho[i]]) {
      dfs(vizinho[i]);
    }
  }
}
void dfs2(int curr) {
  cnt++;
  vis2[curr] = true;
  vector<int> vizinho = graph[curr];
  for (int i = 0; i < vizinho.size(); i++) {
    if (!vis2[vizinho[i]] and !vis[curr]) {
      dfs2(vizinho[i]);
    }
  }
}
int main() {
  int n, m, source;
  vector<pair<int, int>> arr_count;
  cin >> n >> m >> source;
  source--;
  int ans = 0;
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    --x, --y;
    graph[x].push_back(y);
  }
  dfs(source);
  for (int i = 0; i < n; i++) {
    if (!vis[i]) {
      cnt = 0;
      memset(vis2, false, sizeof(vis2));
      dfs2(i);
      arr_count.push_back(make_pair(cnt, i));
    }
  }
  sort(arr_count.begin(), arr_count.end());
  reverse(arr_count.begin(), arr_count.end());
  for (auto it : arr_count) {
    if (!vis[it.second]) {
      ans++;
      dfs(it.second);
      if (it.second == 3) {
      }
    }
  }
  cout << ans << endl;
  return 0;
}
