#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int n, m, cnt, num, sccn, pre[N];
int fir[N], scc[N], dfn[N], low[N], arr[N], nex[N];
stack<int> s;
void dfs(int x) {
  s.push(x);
  dfn[x] = low[x] = ++num;
  for (int i = fir[x]; i; i = nex[i]) {
    int v = arr[i];
    if (!dfn[v]) {
      dfs(v);
      low[x] = min(low[x], low[v]);
    } else if (!scc[v])
      low[x] = min(low[x], dfn[v]);
  }
  if (dfn[x] == low[x]) {
    sccn++;
    while (1) {
      int v = s.top();
      s.pop();
      scc[v] = sccn;
      if (x == v) break;
    }
  }
}
int main() {
  int S;
  scanf("%d%d%d", &n, &m, &S);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    nex[i] = fir[u];
    fir[u] = i;
    arr[i] = v;
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i);
  for (int i = 1; i <= n; i++) {
    for (int j = fir[i]; j; j = nex[j]) {
      if (scc[i] == scc[arr[j]]) continue;
      pre[scc[arr[j]]] = 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= sccn; i++) {
    if (i == scc[S])
      continue;
    else if (!pre[i])
      ans++;
  }
  cout << ans;
  return 0;
}
