#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 1;
vector<int> ok[N];
vector<pair<int, int> > go;
int vis[N], vis2[N], path[N];
void dfs(int node, int start, int t) {
  if (!t) vis[node] = 1;
  if (t) vis2[node] = 1;
  for (int i = 0; i < ok[node].size(); i++) {
    if (!vis[ok[node][i]] && !t) dfs(ok[node][i], start, t);
    if (!vis2[ok[node][i]] && t && !vis[ok[node][i]]) {
      path[start]++;
      dfs(ok[node][i], start, t);
    }
  }
}
int main() {
  int n, m, x;
  scanf("%d%d%d", &n, &m, &x);
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    ok[u].push_back(v);
  }
  dfs(x, 0, 0);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      for (int j = 1; j <= n; j++) vis2[j] = 0;
      dfs(i, i, 1);
      go.push_back(make_pair(-path[i], i));
    }
  }
  sort(go.begin(), go.end());
  for (int i = 0; i < go.size(); i++)
    if (!vis[go[i].second]) {
      ans++;
      dfs(go[i].second, 0, 0);
    }
  printf("%d\n", ans);
  return 0;
}
