#include <bits/stdc++.h>
using namespace std;
const long long inff = 0x3f3f3f3f3f3f3f3f;
int n, m, s, b[5008], a[5008], d[5008];
vector<int> g[5008];
void dfs(int s, int z) {
  b[s] = 1;
  for (int i = 0; i < g[s].size(); i++) {
    if (!b[g[s][i]]) dfs(g[s][i], z + 1);
  }
  if (!z) {
    for (int i(1); i <= (n); ++i) {
      if (d[i] && !b[i]) dfs(i, z + 1);
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> s;
  int x, y;
  while (m--) {
    scanf("%d", &x), scanf("%d", &y);
    a[y]++;
    g[x].push_back(y);
  }
  int ans = 0;
  dfs(s, 0);
  for (int i(1); i <= (n); ++i) {
    if (!b[i]) ans++, d[i] = 1;
  }
  for (int i(1); i <= (n); ++i) {
    if (d[i] && a[i]) {
      memset(b, 0, sizeof(b));
      d[i] = 0;
      dfs(s, 0);
      if (b[i])
        ans--;
      else
        d[i] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}
