#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, m, s;
vector<int> g[N];
bool color[2][N];
vector<pair<int, int> > node;
int cnt;
void dfs(int idx, int from, int add = 0) {
  color[idx][from] = true;
  cnt += add;
  for (int to : g[from]) {
    if (color[idx][to]) continue;
    dfs(idx, to, add);
  }
}
void HalfDead() {
  cin >> n >> m >> s;
  for (int i = 0; i < (int)m; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
  }
  dfs(0, s);
  for (int i = 1; i <= n; ++i) {
    if (color[0][i]) continue;
    cnt = 0;
    memset(color[1], false, sizeof color[1]);
    dfs(1, i, 1);
    node.push_back({cnt, i});
  }
  sort((node).begin(), (node).end());
  reverse((node).begin(), (node).end());
  int res = 0;
  for (auto t : node) {
    int from = t.second;
    if (color[0][from]) continue;
    res += 1;
    dfs(0, from);
  }
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  int tc = 1;
  while (tc--) HalfDead();
  return 0;
}
