#include <bits/stdc++.h>
using namespace std;
vector<int> g[5000];
vector<int> r[5000];
vector<int8_t> vis(5000);
int n, m, s;
void dfs(int src) {
  vis[src] = true;
  for (auto v : g[src]) {
    if (!vis[v]) {
      dfs(v);
    }
  }
}
int root(int src, vector<bool> &df) {
  df[src] = true;
  int c = 0;
  for (int v : g[src]) {
    if (!df[v] && !vis[v]) {
      c += root(v, df) + 1;
    }
  }
  return c;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> s;
  --s;
  for (int x, y, i = 0; i < m; ++i) {
    cin >> x >> y;
    g[--x].push_back(--y);
    r[y].push_back(x);
  }
  dfs(s);
  int ans = 0;
  vector<pair<int, int>> sl;
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      vector<bool> df(n);
      int a = root(i, df);
      sl.push_back({-a, i});
    }
  }
  sort(sl.begin(), sl.end());
  for (auto c : sl) {
    if (!vis[c.second]) {
      g[s].push_back(c.second);
      dfs(s);
      ++ans;
    }
  }
  printf("%d\n", ans);
  return false & true;
}
