#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = -1e-2;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const long long mod = 1e9 + 7;
const int Mx = INT_MAX;
const int Mn = INT_MIN;
const long long MX = LLONG_MAX;
const long long MN = LLONG_MIN;
const int N = 2e5 + 2;
void Open() {}
int cnt = 0;
vector<vector<int>> adj;
bitset<N> vis, vis2;
void dfs(int node) {
  vis[node] = 1;
  for (int next : adj[node]) {
    if (!vis[next]) dfs(next);
  }
}
void dfs2(int node) {
  vis2[node] = 1;
  cnt++;
  for (int next : adj[node]) {
    if (!vis2[next]) dfs2(next);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Open();
  int n, m, s, u, v;
  cin >> n >> m >> s;
  adj.resize(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
  }
  dfs(s);
  vector<pair<int, int>> city;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      vis2.reset();
      cnt = 0;
      dfs2(i);
      city.push_back({cnt, i});
    }
  }
  int ans = 0;
  sort(((city).rbegin()), ((city).rend()));
  for (auto i : city) {
    if (!vis[i.second]) {
      ans++;
      adj[s].push_back(i.second);
      dfs(i.second);
    }
  }
  cout << ans;
}
