#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int n, m, s, f[MAXN], vis[MAXN];
vector<int> G[MAXN];
void dfs(int u, int fa) {
  if (f[u] == fa) return;
  f[u] = fa;
  for (auto i : G[u]) dfs(i, fa);
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
  }
  dfs(s, s);
  for (int i = 1; i <= n; i++)
    if (!f[i]) dfs(i, i);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[f[i]]) vis[f[i]] = 1, ans++;
  printf("%d\n", ans - vis[s]);
  return 0;
}
