#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int M = 1000005;
const int N = 5005;
int n, m, p, i, j, s, tot, ans, low[N], dfn[N], d[N], f[N], fa[N], op, ed, r[N],
    t1, t2;
vector<int> g[N], gg[N];
stack<int> sta;
void tarjan(int x) {
  sta.push(x);
  f[x] = 1;
  dfn[x] = low[x] = ++tot;
  for (auto &i : g[x])
    if (!dfn[i]) {
      tarjan(i);
      low[x] = min(low[x], low[i]);
    } else if (f[i])
      low[x] = min(low[x], dfn[i]);
  if (low[x] == dfn[x]) {
    fa[x] = ++s;
    f[x] = 0;
    while (sta.top() != x) {
      fa[sta.top()] = s;
      f[sta.top()] = 0;
      sta.pop();
    }
    sta.pop();
  }
}
void bfs(int x) {
  memset(f, 0, sizeof(f));
  op = ed = 1;
  d[1] = x;
  f[x] = 1;
  while (op <= ed) {
    for (auto &i : gg[d[op]])
      if (!f[i]) {
        d[++ed] = i;
        f[i] = 1;
      }
    op++;
  }
}
int main() {
  memset(dfn, 0, sizeof(dfn));
  memset(f, 0, sizeof(f));
  memset(r, 0, sizeof(r));
  scanf("%d %d %d", &n, &m, &p);
  for (i = 1; i <= n; i++) fa[i] = i;
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &t1, &t2);
    g[t1].push_back(t2);
  }
  for (i = 1, tot = s = 0; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  for (i = 1; i <= n; i++) {
    for (auto &j : g[i])
      if (fa[j] != fa[i]) {
        gg[fa[i]].push_back(fa[j]);
        r[fa[j]]++;
      }
  }
  bfs(fa[p]);
  for (i = 1, ans = 0; i <= s; i++)
    if (!f[i] && !r[i]) ans++;
  printf("%d\n", ans);
  return 0;
}
