#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
int used[N], used2[N];
vector<int> g[N];
void dfs(int v) {
  used[v] = 1;
  for (int to : g[v]) {
    if (used[to]) {
      continue;
    }
    dfs(to);
  }
}
int dfs2(int v) {
  used2[v] = 1;
  int ret = 1;
  for (int to : g[v]) {
    if (used2[to]) {
      continue;
    }
    ret += dfs2(to);
  }
  return ret;
}
int main() {
  int n, m, s;
  scanf("%d %d %d", &n, &m, &s);
  s--;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
  }
  dfs(s);
  vector<pair<int, int> > ve;
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      memset(used2, 0, sizeof used2);
      int cnt = dfs2(i);
      ve.push_back(make_pair(-cnt, i));
    }
  }
  sort(ve.begin(), ve.end());
  int ans = 0;
  for (auto it : ve) {
    int cnt = -it.first;
    int v = it.second;
    if (!used[v]) {
      ans++;
      dfs(v);
    }
  }
  printf("%d\n", ans);
  return 0;
}
