#include <bits/stdc++.h>
using namespace std;
int dx4[] = {-1, 0, 1, 0};
int dy4[] = {0, 1, 0, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const double eps = (double)1e-10;
const double PI = acos(-1.0);
inline int getint() {
  int x;
  scanf("%d", &x);
  return x;
}
inline long long getlonglong() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int n, m, s;
vector<int> graph[5007];
bool vis[5007], visit[5007];
int cnt = 0;
void dfs(int u) {
  if (vis[u]) return;
  cnt++;
  vis[u] = 1;
  int len = graph[u].size();
  for (int i = 0; i < len; i++) {
    int v = graph[u][i];
    if (!vis[v]) dfs(v);
  }
}
void dfs_s(int u) {
  if (visit[u]) return;
  visit[u] = 1;
  int len = graph[u].size();
  for (int i = 0; i < len; i++) {
    int v = graph[u][i];
    if (!visit[v]) dfs_s(v);
  }
}
int main() {
  n = getint(), m = getint(), s = getint();
  for (int i = 0; i < m; i++) {
    int u = getint(), v = getint();
    graph[u].push_back(v);
  }
  dfs_s(s);
  priority_queue<pair<int, int> > pq;
  for (int i = 1; i <= n; i++) {
    if (i == s) continue;
    cnt = 0;
    memset(vis, 0, sizeof vis);
    if (!visit[i]) dfs(i);
    pq.push(pair<int, int>(cnt, i));
  }
  cnt = 0;
  while (!pq.empty()) {
    int u = pq.top().second;
    if (!visit[u]) {
      dfs_s(u);
      cnt++;
    }
    pq.pop();
  }
  printf("%d\n", cnt);
  return 0;
}
