#include <bits/stdc++.h>
using namespace std;
vector<int> a[100005], kq[100005];
int s[100005], d[100005], v[100005], din[100005];
int n, m, dem, r, n1, k, s1, vt;
void nhap() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> s1;
  int u, v;
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v;
    a[u].push_back(v);
  }
}
int dfs(int x) {
  ++dem;
  d[x] = dem;
  ++r;
  s[r] = x;
  int min1 = d[x];
  for (int i = 0; i < a[x].size(); ++i)
    if (d[a[x][i]] == 0)
      min1 = min(min1, dfs(a[x][i]));
    else if (d[a[x][i]] > 0)
      min1 = min(min1, d[a[x][i]]);
  if (min1 >= d[x]) {
    ++n1;
    while (s[r] != x) {
      if (s[r] == s1) vt = n1;
      kq[n1].push_back(s[r]);
      d[s[r]] = -1;
      v[s[r]] = n1;
      --r;
    }
    kq[n1].push_back(x);
    if (s[r] == s1) vt = n1;
    d[x] = -1;
    v[x] = n1;
    --r;
  }
  return min1;
}
void xl() {
  for (int i = 1; i <= n; ++i)
    if (d[i] == 0) {
      int x = dfs(i);
      x = 1;
    }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < a[i].size(); ++j)
      if (v[i] != v[a[i][j]]) ++din[v[a[i][j]]];
  }
  for (int i = 1; i <= n1; ++i)
    if (din[i] == 0 && i != vt) ++k;
  cout << k;
}
int main() {
  nhap();
  xl();
  return 0;
}
