#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
vector<int> v[N], vt[N], scc[N];
bool viz[N];
stack<int> comp;
int nr, from[N], gr[N];
void dfp(int i) {
  viz[i] = 1;
  for (auto it : v[i])
    if (!viz[it]) dfp(it);
  comp.push(i);
}
void dfm(int i) {
  scc[nr].push_back(i);
  viz[i] = 1;
  for (auto it : vt[i])
    if (!viz[it]) dfm(it);
}
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    vt[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    if (!viz[i]) dfp(i);
  memset(viz, 0, sizeof(viz));
  while (!comp.empty()) {
    int now = comp.top();
    comp.pop();
    if (!viz[now]) {
      nr++;
      dfm(now);
    }
  }
  int ans = 0;
  for (int i = 1; i <= nr; i++)
    for (auto it : scc[i]) from[it] = i;
  for (int i = 1; i <= n; i++)
    for (auto it : v[i])
      if (from[it] != from[i]) gr[from[it]]++;
  for (int i = 1; i <= nr; i++) {
    bool ok = 1;
    for (auto it : scc[i])
      if (it == s) ok = 0;
    if (ok && gr[i] == 0) ans++;
  }
  cout << ans;
}
