#include <bits/stdc++.h>
using namespace std;
int _gcd(int x, int y) {
  if (y == 0) return x;
  if (x < y) return _gcd(x, y % x);
  return _gcd(y, x % y);
}
long long int _pow(unsigned long long int x, unsigned long long int y) {
  long long int res = 1;
  x = x % (1000000000 + 7);
  while (y > 0) {
    if (y & 1) res = (res * x) % (1000000000 + 7);
    y = y >> 1;
    x = (x * x) % (1000000000 + 7);
  }
  return res;
}
void findDiv(int n, vector<int>& div) {
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (i != (n / i)) {
        div.push_back(i);
        div.push_back(n / i);
      } else
        div.push_back(i);
    }
  }
}
void dfs(vector<vector<int>>& graph, int visited[], int node) {
  visited[node] = 1;
  for (int i = 0; i < graph[node].size(); i++) {
    if (!visited[graph[node][i]]) dfs(graph, visited, graph[node][i]);
  }
}
void _dfs(vector<vector<int>>& graph, int visited[], int node, int root) {
  if (root != node) visited[node] = 1;
  for (int i = 0; i < graph[node].size(); i++) {
    if (!visited[graph[node][i]]) _dfs(graph, visited, graph[node][i], root);
  }
}
int main() {
  int n, m, c;
  cin >> n >> m >> c;
  c--;
  int visited1[n], visited2[n];
  for (int i = 0; i < n; i++) visited1[i] = visited2[i] = 0;
  vector<vector<int>> graph(n + 1);
  while (m--) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
  }
  dfs(graph, visited1, c);
  for (int i = 0; i < n; i++)
    if (!visited1[i]) {
      for (int ind = 0; ind < n; ind++) visited2[ind] = false;
      _dfs(graph, visited2, i, i);
      for (int ind = 0; ind < n; ind++)
        if (visited2[ind]) visited1[ind] = true;
    }
  long long int ans = 0;
  for (int i = 0; i < n; i++)
    if (!visited1[i]) ans++;
  cout << ans << "\n";
  return 0;
}
