#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f, NegOO = -1 * OO, N = 5e3 + 5, mod = 1e10 + 7;
int n, m, s, x, z;
vector<int> vec[N];
bool reach[N];
bool vis[N];
int color[N];
void DFS(int node) {
  if (vis[node]) return;
  vis[node] = 1;
  for (int c = 0; c < vec[node].size(); c++) {
    int nnode = vec[node][c];
    if (!vis[nnode]) {
      reach[nnode] = 1;
      DFS(nnode);
    }
  }
}
void ColorDFS(int node, int clr) {
  if (vis[node]) return;
  vis[node] = 1;
  for (int c = 0; c < vec[node].size(); c++) {
    int nnode = vec[node][c];
    if (!vis[nnode]) {
      color[nnode] = clr;
      ColorDFS(nnode, clr);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0), ios::sync_with_stdio(0), cin.tie(0),
      cout.tie(0);
  memset(color, -1, sizeof color);
  cin >> n >> m >> s;
  for (int c = 0; c < m; c++) {
    cin >> x >> z;
    vec[x].push_back(z);
  }
  reach[s] = 1;
  DFS(s);
  int numcolor = 0;
  for (int c = 1; c < n + 1; c++) {
    if (!reach[c] && color[c] == -1) {
      memset(vis, 0, sizeof vis);
      color[c] = numcolor;
      ColorDFS(c, numcolor);
      numcolor++;
    }
  }
  set<int> s;
  for (int c = 1; c < n + 1; c++) {
    if (color[c] != -1) {
      s.insert(color[c]);
    }
  }
  cout << ((int)((s).size())) << "\n";
  return 0;
}
