#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9;
const int MAX = 1e5 + 7, N = 1e5 + 3;
double pi = cos(-1);
int r, l, k, m, n, ans;
bool visited1[10000];
bool visited2[10000];
vector<pair<int, int> > uv;
int h[10000];
vector<vector<int> > graph;
int s;
list<int> bfslist;
int sour;
bool done;
void bfs(int v) {
  for (int i = 0; i < graph[v].size(); i++) {
    if (visited1[graph[v][i]] or visited2[graph[v][i]]) continue;
    bfslist.push_back(graph[v][i]);
    visited1[graph[v][i]] = true;
    done = true;
  }
}
void bfs2(int v) {
  for (int i = 0; i < graph[v].size(); i++) {
    if (visited1[graph[v][i]] or visited2[graph[v][i]]) continue;
    bfslist.push_back(graph[v][i]);
    visited2[graph[v][i]] = true;
    h[sour]++;
  }
}
int main() {
  cin >> n >> m >> s;
  graph.assign(n + 2, vector<int>());
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
  }
  bfslist.push_back(s);
  visited1[s] = true;
  while (!bfslist.empty()) {
    int v = bfslist.front();
    bfslist.pop_front();
    bfs(v);
  }
  for (int i = 1; i <= n; i++) {
    if (visited1[i]) continue;
    bfslist.push_back(i);
    memset(visited2, 0, sizeof(visited2));
    visited2[i] = true;
    sour = i;
    while (!bfslist.empty()) {
      int v = bfslist.front();
      bfslist.pop_front();
      bfs2(v);
    }
    uv.push_back(make_pair(-1 * h[sour], sour));
  }
  memset(visited2, 0, sizeof(visited2));
  sort(uv.begin(), uv.end());
  for (int i = 0; i < uv.size(); i++) {
    if (visited1[uv[i].second]) continue;
    bfslist.push_back(uv[i].second);
    visited1[uv[i].second] = true;
    while (!bfslist.empty()) {
      int v = bfslist.front();
      bfslist.pop_front();
      bfs(v);
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}
