#include <bits/stdc++.h>
using namespace std;
void dfs(std::vector<int> adj[], int n, int source, std::vector<bool> &visited,
         std::vector<int> reachable[]) {
  stack<int> s;
  s.push(source);
  while (!s.empty()) {
    int t = s.top();
    s.pop();
    if (!visited[t]) {
      visited[t] = true;
      reachable[source].push_back(t);
    }
    for (int i = 0; i < adj[t].size(); i++) {
      if (!visited[adj[t][i]]) {
        s.push(adj[t][i]);
      }
    }
  }
}
bool greaterReachable(pair<int, int> p1, pair<int, int> p2) {
  return p1.second > p2.second;
}
int main() {
  int n, m, s, u, v, flag = 0, edge = 0;
  cin >> n >> m >> s;
  n++;
  std::vector<bool> visited(n, false);
  std::vector<int> adj[n], reachable[n];
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
  }
  dfs(adj, n, s, visited, reachable);
  for (int i = 0; i < n; i++) {
    if (!visited[i]) {
      flag = 1;
      break;
    }
  }
  std::vector<pair<int, int> > ct;
  std::vector<int> graph[n];
  int cnt = 0, maxCnt = 0, add = 0;
  for (int i = 1; i < n; i++) {
    int x = 0;
    std::vector<bool> vis(n, false);
    cnt = 0;
    if (!visited[i]) {
      dfs(adj, n, i, vis, reachable);
      for (int j = 0; j < reachable[i].size(); j++) {
        if (!visited[reachable[i][j]]) cnt++;
      }
      ct.push_back(make_pair(i, cnt));
      if (cnt >= maxCnt) {
        maxCnt = cnt;
        add = i;
      }
    }
  }
  sort(ct.begin(), ct.end(), greaterReachable);
  for (int i = 0; i < ct.size(); i++) {
    if (!visited[ct[i].first]) {
      visited[ct[i].first] = true;
      for (int j = 0; j < reachable[ct[i].first].size(); j++) {
        visited[reachable[ct[i].first][j]] = true;
      }
      edge++;
    }
  }
  cout << edge << endl;
  return 0;
}
