#include <bits/stdc++.h>
using namespace std;
vector<int> adj[500010], ar;
bool vis[500010];
int u, v, n, m, s, res = 0;
void dfs(int cur) {
  vis[cur] = true;
  for (auto i : adj[cur])
    if (!vis[i]) dfs(i);
  ar.push_back(cur);
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
  }
  dfs(s);
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) dfs(i);
  }
  memset(vis, false, sizeof vis);
  for (int i = n - 1; i >= 0; --i) {
    if (!vis[ar[i]]) {
      if (s != ar[i]) res++;
      dfs(ar[i]);
    }
  }
  printf("%d\n", res);
  return 0;
}
