#include <bits/stdc++.h>
using namespace std;
const int MaxN = 5000 + 5;
const int MaxM = 5000 + 5;
struct Graph {
  int cnte;
  int Head[MaxN], To[MaxM], Next[MaxM];
  Graph() {
    cnte = 0;
    memset(Head, 0, sizeof Head);
    memset(To, 0, sizeof To);
    memset(Next, 0, sizeof Next);
  }
  inline void add_edge(int from, int to) {
    cnte++;
    To[cnte] = to;
    Next[cnte] = Head[from];
    Head[from] = cnte;
  }
};
struct Stack {
  int st[MaxN * 2], sz;
  Stack() {
    memset(st, 0, sizeof st);
    sz = 0;
  }
  inline int size() { return sz; }
  inline bool empty() { return sz == 0; }
  inline int top() { return st[sz]; }
  inline void pop() { sz--; }
  inline void push(int x) { st[++sz] = x; }
};
int N, M, S;
int cntv, V;
Graph G, DAG;
int X[MaxM], Y[MaxM];
int low[MaxN], dfn[MaxN];
int lnk[MaxN];
bool in_stack[MaxN];
Stack st;
bool vis[MaxN];
int ind[MaxN];
void init() {
  scanf("%d %d %d", &N, &M, &S);
  for (int i = 1; i <= M; ++i) {
    int &u = X[i], &v = Y[i];
    scanf("%d %d", &u, &v);
    G.add_edge(u, v);
  }
}
void Tarjan(int u) {
  st.push(u);
  in_stack[u] = true;
  low[u] = dfn[u] = ++cntv;
  for (int i = G.Head[u]; i; i = G.Next[i]) {
    int v = G.To[i];
    if (dfn[v] == 0) {
      Tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (in_stack[v] == true)
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    V++;
    int v;
    do {
      v = st.top();
      st.pop();
      lnk[v] = V;
      in_stack[v] = false;
    } while (v != u);
  }
}
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = true;
  for (int i = DAG.Head[u]; i; i = DAG.Next[i]) dfs(DAG.To[i]);
}
void solve() {
  for (int i = 1; i <= N; ++i)
    if (dfn[i] == 0) Tarjan(i);
  for (int i = 1; i <= M; ++i) {
    int u = X[i], v = Y[i];
    if (lnk[u] == lnk[v]) continue;
    DAG.add_edge(lnk[u], lnk[v]);
    ind[lnk[v]]++;
  }
  dfs(lnk[S]);
  int ans = 0;
  for (int i = 1; i <= V; ++i)
    if (ind[i] == 0 && vis[i] == false) dfs(i), ans++;
  for (int i = 1; i <= V; ++i)
    if (vis[i] == false) dfs(i), ans++;
  cout << ans << endl;
}
int main() {
  init();
  solve();
  return 0;
}
