#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> graph;
vector<bool> visited;
vector<long long> sorted;
void dfs(long long source) {
  visited[source] = true;
  for (auto i : graph[source]) {
    if (!visited[i]) dfs(i);
  }
  sorted.push_back(source);
}
void topologicalSort() {
  visited.resize(graph.size(), false);
  for (long long i = 0; i < graph.size(); i++) {
    if (!visited[i]) dfs(i);
  }
  reverse(sorted.begin(), sorted.end());
}
void solveCase() {
  long long n = 0, m = 0, s = 0;
  cin >> n >> m >> s;
  graph.resize(n);
  while (m--) {
    long long u = 0, v = 0;
    cin >> u >> v;
    graph[u - 1].push_back(v - 1);
  }
  topologicalSort();
  visited.clear();
  visited.resize(n, false);
  dfs(s - 1);
  long long connected = 1;
  for (auto i : sorted) {
    if (visited[i]) continue;
    dfs(i);
    connected++;
  }
  cout << connected - 1 << "\n";
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solveCase();
}
