#include <bits/stdc++.h>
using namespace std;
const int N = 5001;
bool yes[N];
vector<int> adj[N];
void dfs(int u) {
  if (yes[u]) return;
  yes[u] = 1;
  for (auto el : adj[u]) dfs(el);
}
bool vis[N];
priority_queue<pair<int, int>> ss;
int cnt(int u) {
  if (vis[u]) return 0;
  vis[u] = 1;
  int res = 0;
  for (auto el : adj[u])
    if (!yes[el]) res += cnt(el);
  return res + 1;
}
void yess(int u) {
  if (yes[u]) return;
  yes[u] = 1;
  for (auto el : adj[u]) yess(el);
}
int main() {
  int n, m, s;
  scanf("%d %d %d", &n, &m, &s);
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    u--, v--;
    adj[u].push_back(v);
  }
  s--;
  dfs(s);
  for (int i = 0; i < n; i++) {
    if (!yes[i]) {
      memset(vis, 0, sizeof(vis));
      ss.push({cnt(i), i});
    }
  }
  int res = 0;
  while (!ss.empty()) {
    pair<int, int> pr = ss.top();
    ss.pop();
    if (yes[pr.second]) continue;
    res++;
    yess(pr.second);
  }
  cout << res;
}
