#include <bits/stdc++.h>
using namespace std;
vector<int>* p;
bool vis[5000];
stack<int> st;
void dfs(int src) {
  vis[src] = true;
  for (auto w : p[src]) {
    if (!vis[w]) dfs(w);
  }
}
int root(int src) {
  vis[src] = true;
  st.push(src);
  int c = 0;
  for (auto w : p[src])
    if (!vis[w]) {
      c += 1 + root(w);
    }
  return c;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, s, res = 0;
  cin >> n >> m >> s;
  --s;
  vector<int> g[n];
  p = g;
  for (int x, y, i = 0; i < m; ++i) {
    cin >> x >> y;
    g[--x].push_back(--y);
  }
  dfs(s);
  vector<pair<int, int>> sl;
  for (int i = 0; i < n; ++i) {
    if (!vis[i]) {
      sl.push_back({root(i), i});
      while (st.size()) {
        vis[st.top()] = false;
        st.pop();
      }
    }
  }
  sort(sl.begin(), sl.end(), greater<pair<int, int>>());
  for (auto point : sl) {
    if (!vis[point.second]) {
      dfs(point.second);
      ++res;
    }
  }
  printf("%d\n", res);
  return false & true;
}
