#include <bits/stdc++.h>
using namespace std;
int vis[5005];
vector<int> ve[5005];
stack<int> st;
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < ve[x].size(); i++) {
    int xx = ve[x][i];
    if (!vis[xx]) {
      dfs(xx);
    }
  }
  st.push(x);
}
void bfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < ve[x].size(); i++) {
    int xx = ve[x][i];
    if (!vis[xx]) {
      dfs(xx);
    }
  }
}
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    ve[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  memset(vis, 0, sizeof(vis));
  bfs(s);
  int ans = 0;
  while (st.empty() != 1) {
    int x = st.top();
    st.pop();
    if (!vis[x]) {
      ans++;
      dfs(x);
    }
  }
  cout << ans << endl;
  return 0;
}
