#include <bits/stdc++.h>
using namespace std;
int n, m, s, ans;
vector<int> edg[5005];
bool vis[5005];
vector<pair<int, int> > st;
vector<int> gr[5005], rg[5005], comp[5005];
int compInd = 0, ind = 0, indInComp[5005], compNum[5005];
bool vis1[5005], vis2[5005];
stack<int> ord;
int cnt[5005];
void dfs(int x) {
  vis[x] = true;
  for (int j = 0; j < (int)edg[x].size(); j++) {
    if (!vis[edg[x][j]]) dfs(edg[x][j]);
  }
}
map<int, int> tempSt;
int tempInd = 0;
void dfs1(int i) {
  vis1[i] = true;
  for (int j = 0; j < (int)gr[i].size(); j++) {
    if (!vis1[gr[i][j]]) {
      dfs1(gr[i][j]);
    }
  }
  ord.push(i);
}
void dfs2(int i) {
  comp[compInd].push_back(i);
  vis2[i] = true;
  indInComp[i] = ind;
  compNum[i] = compInd;
  ind++;
  for (int j = 0; j < (int)rg[i].size(); j++) {
    if (!vis2[rg[i][j]]) {
      dfs2(rg[i][j]);
    }
  }
}
vector<int> temp[5005];
bool visAns[5005];
void dfsAns(int i) {
  visAns[i] = true;
  for (int j = 0; j < (int)temp[i].size(); j++) {
    if (!visAns[temp[i][j]]) dfsAns(temp[i][j]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int precision = numeric_limits<long double>::digits10;
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    edg[u].push_back(v);
    st.push_back(make_pair(u, v));
  }
  dfs(s);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      tempInd++;
      tempSt[i] = tempInd;
    }
  }
  n = tempInd;
  for (int i = 0; i < (int)st.size(); i++) {
    if (!vis[st[i].first] and !vis[st[i].second]) {
      int u = tempSt[st[i].first], v = tempSt[st[i].second];
      gr[u].push_back(v);
      rg[v].push_back(u);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis1[i]) dfs1(i);
  }
  while ((int)ord.size() != 0) {
    if (!vis2[ord.top()]) {
      compInd++;
      ind = 0;
      dfs2(ord.top());
    }
    ord.pop();
  }
  for (int i = 0; i < (int)st.size(); i++) {
    if (!vis[st[i].first] and !vis[st[i].second]) {
      int u = compNum[tempSt[st[i].first]], v = compNum[tempSt[st[i].second]];
      temp[u].push_back(v);
    }
  }
  for (int i = 1; i <= compInd; i++) {
    if (!visAns[i]) {
      dfsAns(i);
      ans++;
    }
  }
  cout << ans << "\n";
}
