#include <bits/stdc++.h>
int n, m;
using namespace std;
vector<int> used(5005, 0);
vector<int> used2(5005, 0);
int jlo1 = 3;
vector<int> a;
long long res = 0;
vector<vector<int>> graph(5005, a);
vector<int> b;
vector<vector<int>> graph1(5005, b);
int q = 0;
bool flag = false;
void dfs(int p) {
  {
    q++;
    used[p] = 1;
    for (int i = 0; i < graph[p].size(); i++) {
      if (!used[graph[p][i]]) dfs(graph[p][i]);
    }
  }
}
void dfs2(int p) {
  {
    q++;
    used2[p] = 1;
    for (int i = 0; i < graph[p].size(); i++) {
      if (!used2[graph[p][i]]) dfs2(graph[p][i]);
    }
  }
}
int main() {
  int k, t, t1;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    cin >> t >> t1;
    graph[t].push_back(t1);
  }
  dfs(k);
  vector<pair<int, int>> p_q;
  for (int i = 1; i <= n; i++) {
    if (!used[i]) {
      used2.assign(5005, 0);
      q = 0;
      dfs2(i);
      p_q.push_back(make_pair(q, i));
    }
  }
  sort(p_q.rbegin(), p_q.rend());
  long long res = 0;
  for (int i = 0; i < p_q.size(); i++) {
    if (!used[p_q[i].second]) {
      res++;
      dfs(p_q[i].second);
    }
  }
  cout << res << "\n";
  return 0;
}
