#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
struct edge {
  int t, next;
} edges[MAXN];
int head[MAXN], top;
void add(int f, int t) {
  edges[++top].next = head[f];
  edges[top].t = t;
  head[f] = top;
}
int dfn[MAXN], low[MAXN], dfn_cnt, col[MAXN], color;
bool vis[MAXN];
stack<int> stk;
void tarjan(int x) {
  dfn[x] = low[x] = ++dfn_cnt;
  vis[x] = true;
  stk.push(x);
  for (int i = head[x]; i; i = edges[i].next) {
    int t = edges[i].t;
    if (!dfn[t]) {
      tarjan(t);
      low[x] = min(low[x], low[t]);
    } else if (vis[t]) {
      low[x] = min(low[x], dfn[t]);
    }
  }
  if (dfn[x] == low[x]) {
    col[x] = ++color;
    vis[x] = false;
    while (stk.top() != x) {
      col[stk.top()] = color;
      vis[stk.top()] = false;
      stk.pop();
    }
    stk.pop();
  }
}
int indeg[MAXN];
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  int f, t;
  for (int i = 1; i <= m; i++) {
    cin >> f >> t;
    add(f, t);
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  for (int j = 1; j <= n; j++) {
    for (int i = head[j]; i; i = edges[i].next) {
      int t = edges[i].t;
      if (col[t] != col[j]) indeg[col[t]]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= color; i++) {
    if (!indeg[i] && i != col[s]) ans++;
  }
  cout << ans;
  return 0;
}
