#include <bits/stdc++.h>
using namespace std;
int n, m, s, ans;
vector<int> g[5002];
bool f[5002], vis[5002], vv[5002];
void dfs(int u) {
  vis[u] = vv[u] = 1;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!vis[v]) {
      f[v] = 0;
      dfs(v);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  int u, v;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  dfs(s);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) f[i] = 1;
  memcpy(vv, vis, sizeof(vis));
  for (int i = 1; i <= n; i++)
    if (!vv[i]) {
      memset(vis, 0, sizeof(vis));
      dfs(i);
    }
  for (int i = 1; i <= n; i++)
    if (f[i]) ans++;
  printf("%d", ans);
}
