#include <bits/stdc++.h>
using namespace std;
vector<int> g[(int)1e4 + 10];
int dfn[(int)1e4 + 10], low[(int)1e4 + 10], col[(int)1e4 + 10],
    s[(int)1e4 + 10];
bool visit[(int)1e4 + 10];
int cnt, top, idx;
void tarjan(int now) {
  dfn[now] = low[now] = ++cnt;
  visit[now] = true;
  s[++top] = now;
  int i;
  for (i = 0; i < g[now].size(); i++) {
    int temp = g[now][i];
    if (!dfn[temp]) {
      tarjan(temp);
      low[now] = min(low[now], low[temp]);
    } else if (visit[temp]) {
      low[now] = min(low[now], dfn[temp]);
    }
  }
  if (low[now] == dfn[now]) {
    idx++;
    while (s[top] != now) {
      visit[s[top]] = false;
      col[s[top]] = idx;
      top--;
    }
    visit[now] = false;
    col[now] = idx;
    top--;
  }
}
int main(void) {
  int n, m, st;
  scanf("%d%d%d", &n, &m, &st);
  int i, j;
  for (i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
  }
  for (i = 1; i <= n; i++) {
    if (!dfn[i]) tarjan(i);
  }
  int d[(int)1e4 + 10];
  for (i = 1; i <= n; i++) {
    for (j = 0; j < g[i].size(); j++) {
      if (col[i] == col[g[i][j]]) continue;
      d[col[g[i][j]]]++;
    }
  }
  int res = 0;
  for (i = 1; i <= idx; i++) {
    if (d[i] == 0 && i != col[st]) res++;
  }
  printf("%d", res);
}
