#include <bits/stdc++.h>
using namespace std;
const int N = 5020;
int nex[N], head[N], to[N];
int dfn[N], low[N], tim, tp, scc, cnt;
int sta[N], ins[N], rd[N], inscc[N];
void add(int x, int y) {
  nex[++cnt] = head[x];
  head[x] = cnt;
  to[cnt] = y;
}
void tarjan(int u) {
  dfn[u] = low[u] = ++tim;
  sta[++tp] = u;
  ins[u] = 1;
  for (int i = head[u]; i; i = nex[i]) {
    int v = to[i];
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (ins[v])
      low[u] = min(low[u], dfn[v]);
  }
  if (low[u] == dfn[u]) {
    ++scc;
    int k;
    do {
      k = sta[tp--];
      inscc[k] = scc;
      ins[k] = 0;
    } while (k != u);
  }
}
int main() {
  int n, m, s, x, y;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) scanf("%d%d", &x, &y), add(x, y);
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  for (int i = 1; i <= n; i++)
    for (int j = head[i]; j; j = nex[j])
      if (inscc[i] != inscc[to[j]]) rd[inscc[to[j]]]++;
  int ans = 0;
  for (int i = 1; i <= scc; i++)
    if (!rd[i] && i != inscc[s]) ans++;
  printf("%d", ans);
  return 0;
}
