#include <bits/stdc++.h>
using namespace std;
vector<int> gr[100500];
vector<int> grt[100500];
vector<int> order;
int clr[100600];
int res = 0;
int num = 0;
int compn[100500];
int good[100500];
void dfs1(int u) {
  clr[u] = 1;
  for (auto v : gr[u]) {
    if (!clr[v]) {
      dfs1(v);
    }
  }
  order.push_back(u);
}
void dfs2(int u) {
  clr[u] = 0;
  compn[u] = num;
  for (auto v : grt[u]) {
    if (clr[v]) {
      dfs2(v);
    }
    if (compn[u] != compn[v]) {
      good[compn[u]] = 1;
    }
  }
}
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  while (m--) {
    int a, b;
    cin >> a >> b;
    gr[a].push_back(b);
    grt[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!clr[i]) {
      dfs1(i);
    }
  }
  reverse(order.begin(), order.end());
  for (auto v : order) {
    if (clr[v]) {
      dfs2(v);
      ++num;
    }
  }
  int res = 0;
  for (int i = 0; i < num; i++) {
    res += (!good[i]) * (i != compn[s]);
  }
  cout << res << endl;
  return 0;
}
