#include <bits/stdc++.h>
using namespace std;
int read() {
  char x = getchar();
  int ans = 0, flag = 1;
  while (!isdigit(x))
    if (x == '-')
      flag = -1, x = getchar();
    else
      x = getchar();
  while (isdigit(x)) ans = ans * 10 + x - '0', x = getchar();
  return ans * flag;
}
int pnt[5005], nxt[5005], head[5005], E, Head[5005], Pnt[5005], Nxt[5005], e,
    ans;
int stck[5005], top, low[5005], dfn[5005], t, vis[5005], col[5005], n, m, s,
    in[5005];
struct node {
  int u, v;
} ed[5005];
void add_edge(int u, int v) {
  pnt[E] = v;
  nxt[E] = head[u];
  head[u] = E++;
}
void tarjan(int u) {
  dfn[u] = low[u] = ++t;
  vis[u] = 1;
  stck[++top] = u;
  for (int i = head[u]; i != -1; i = nxt[i]) {
    int v = pnt[i];
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (vis[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (dfn[u] == low[u]) {
    while (stck[top] != u) {
      vis[stck[top]] = 0;
      col[stck[top]] = u;
      top--;
    }
    vis[stck[top]] = 0;
    col[stck[top]] = u;
    top--;
  }
}
void Add_edge(int u, int v) {
  Pnt[e] = v;
  Nxt[e] = Head[u];
  Head[u] = e++;
}
void dfs(int u, int pre) {
  if (vis[u]) return;
  vis[u] = 1;
  for (int i = Head[u]; i != -1; i = Nxt[i]) {
    int v = Pnt[i];
    if (v == pre) continue;
    dfs(v, u);
  }
}
signed main() {
  memset(Head, -1, sizeof(Head));
  memset(head, -1, sizeof(head));
  n = read(), m = read(), s = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    ed[i] = (node){u, v};
    add_edge(u, v);
  }
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) tarjan(i);
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= m; i++) {
    int u = ed[i].u, v = ed[i].v;
    if (col[u] == col[v]) continue;
    Add_edge(col[u], col[v]);
    in[col[v]]++;
  }
  dfs(col[s], 0);
  for (int i = 1; i <= n; i++) {
    if (col[i] == i && !in[i] && !vis[i]) {
      dfs(i, 0);
      ans++;
    }
  }
  cout << ans;
  return 0;
}
