#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, m, s;
vector<int> e[N];
int low[N], dfn[N], idx;
bool vis[N];
stack<int> st;
bool in_stack[N];
int color[N], color_tot;
int indeg[N];
int ans;
void AddEdge(int u, int v) { e[u].push_back(v); }
void Dfs(int u) {
  low[u] = dfn[u] = ++idx;
  in_stack[u] = true;
  st.push(u);
  for (int v : e[u]) {
    if (!dfn[v]) {
      Dfs(v);
      low[u] = min(low[u], low[v]);
    } else if (in_stack[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (low[u] == dfn[u]) {
    ++color_tot;
    int v;
    do {
      v = st.top();
      st.pop();
      in_stack[v] = false;
      color[v] = color_tot;
    } while (v != u);
  }
}
void Tarjan() {
  for (int i = 1; i <= n; ++i)
    if (!color[i]) Dfs(i);
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    AddEdge(u, v);
  }
  Tarjan();
  for (int i = 1; i <= n; ++i)
    ;
  for (int i = 1; i <= n; ++i)
    for (int j : e[i])
      if (color[i] != color[j]) ++indeg[color[j]];
  for (int i = 1; i <= color_tot; ++i)
    ;
  for (int i = 1; i <= color_tot; ++i)
    if (indeg[i] == 0) ++ans;
  if (indeg[color[s]] == 0) --ans;
  printf("%d\n", ans);
  return 0;
}
