#include <bits/stdc++.h>
using namespace std;
int TM;
int n, m, s, cl;
vector<int> G[5003], Q[5003];
int vis[5003];
bool ok[5003];
bool fcc, flc;
void chk(int u) {
  if (ok[u]) return;
  ok[u] = 1;
  for (int i = 0; i < Q[u].size(); i++) chk(Q[u][i]);
  return;
}
int dfs(int u) {
  if (u == s) return 0;
  if (vis[u]) {
    if (vis[u] == cl)
      fcc = 1;
    else
      flc = 1;
    return 0;
  }
  vis[u] = cl;
  if (G[u].size() == 0) return 1;
  int res = 0;
  for (int i = 0; i < G[u].size(); i++) res += dfs(G[u][i]);
  return res;
}
int main() {
  int u, v;
  cin >> n >> m >> s;
  while (m--) {
    cin >> u >> v;
    Q[u].push_back(v);
    G[v].push_back(u);
  }
  chk(s);
  int ans = 0;
  for (int u = 1; u <= n; u++) {
    if (ok[u]) continue;
    if (vis[u]) continue;
    cl++;
    fcc = 0;
    flc = 0;
    int cur = dfs(u);
    ans += cur;
    if (cur == 0 && fcc && !flc) ans++;
  }
  cout << ans;
}
