#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<vector<int> > g;
vector<bool> u1, u2;
int c = 0;
void dfs1(int v) {
  u1[v] = 1;
  for (auto i : g[v])
    if (!u1[i]) dfs1(i);
}
void dfs2(int v) {
  ++c;
  u2[v] = 1;
  for (auto i : g[v])
    if (!u2[i]) dfs2(i);
}
int main() {
  ios_base::sync_with_stdio(0);
  int ans = 0, n, m, s;
  vector<pair<int, int> > q;
  cin >> n >> m >> s;
  --s;
  g.resize(n);
  u1.assign(n, 0);
  u2.assign(n, 0);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
  }
  dfs1(s);
  for (int i = 0; i < n; ++i)
    if (!u1[i]) {
      c = 0;
      dfs2(i);
      q.push_back({-c, i});
      u2.assign(n, 0);
    }
  sort(q.begin(), q.end());
  u1.assign(n, 0);
  for (auto i : q)
    if (!u1[i.second]) {
      dfs1(i.second);
      ++ans;
    }
  cout << ans;
}
