#include <bits/stdc++.h>
using namespace std;
std::vector<int> G[5005];
int vis[5005], vis1[5005];
stack<int> stk;
void dfs(int u) {
  vis[u] = 1;
  for (int v : G[u]) {
    if (!vis[v]) dfs(v);
  }
  stk.push(u);
}
void dfs1(int u) {
  vis1[u] = 1;
  for (int v : G[u]) {
    if (!vis1[v]) dfs1(v);
  }
}
int main(int argc, char const *argv[]) {
  int n, m, C;
  cin >> n >> m >> C;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
  }
  dfs1(C);
  for (int i = 1; i < n + 1; ++i) vis[i] = vis1[i];
  for (int i = 1; i < n + 1; ++i) {
    if (vis[i]) continue;
    dfs(i);
  }
  std::vector<int> dep;
  while (!stk.empty()) {
    dep.push_back(stk.top());
    stk.pop();
  }
  int c = 0;
  for (int i : dep) {
    if (!vis1[i]) {
      c++;
      dfs1(i);
    }
  }
  cout << c << endl;
  return 0;
}
