#include <bits/stdc++.h>
using namespace std;
int n, m, s, a, b;
vector<int> adjlist[5001];
vector<int> jdalist[5001];
vector<pair<int, int> > edgelist;
vector<int> compadj[5001];
stack<int> nodes;
int indegree[5001];
bool vis[5001];
int cnt = 0;
int compval[5001];
void dfs(int node) {
  if (!vis[node]) {
    vis[node] = true;
    for (int i = 0; i < adjlist[node].size(); i++) dfs(adjlist[node][i]);
  }
}
void pushstackdfs(int node) {
  if (!vis[node]) {
    vis[node] = true;
    for (int i = 0; i < adjlist[node].size(); i++)
      pushstackdfs(adjlist[node][i]);
    nodes.push(node);
  }
}
void setdfs(int node, int ccval) {
  if (!vis[node]) {
    vis[node] = true;
    compval[node] = ccval;
    for (int i = 0; i < jdalist[node].size(); i++) {
      setdfs(jdalist[node][i], ccval);
    }
  }
}
void compdfs(int node) {
  if (!vis[node]) {
    vis[node] = true;
    for (int i = 0; i < compadj[node].size(); i++) compdfs(compadj[node][i]);
  }
}
int main() {
  cin >> n >> m >> s;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    adjlist[a].push_back(b);
    jdalist[b].push_back(a);
    edgelist.push_back(make_pair(a, b));
  }
  for (int i = 0; i <= n; i++) vis[i] = false;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      pushstackdfs(i);
    }
  }
  for (int i = 0; i <= n; i++) vis[i] = false;
  int cc = 0;
  while (!nodes.empty()) {
    int curnode = nodes.top();
    nodes.pop();
    if (!vis[curnode]) {
      setdfs(curnode, cc);
      cc++;
    }
  }
  for (int i = 0; i < edgelist.size(); i++) {
    if (compval[edgelist[i].first] != compval[edgelist[i].second]) {
      compadj[compval[edgelist[i].first]].push_back(
          compval[edgelist[i].second]);
      indegree[compval[edgelist[i].second]]++;
    }
  }
  for (int i = 0; i < cc; i++) vis[i] = false;
  compdfs(compval[s]);
  for (int i = 0; i < cc; i++) {
    if (indegree[i] == 0 && !vis[i]) {
      compdfs(i);
      cnt++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      compdfs(i);
      cnt++;
    }
  }
  cout << cnt << '\n';
}
