#include <bits/stdc++.h>
#pragma GCC optimize("O2")
long long bigmod(long long a, long long b) {
  if (b == 0) return 1;
  long long ret = bigmod(a, b / 2);
  return ret * ret % 1000000007 * (b % 2 ? a : 1) % 1000000007;
}
using namespace std;
pair<int, int> p[5010];
int n, m, k;
queue<int> Q;
int vis[5010], Pr[5010];
vector<int> E[5010];
int ata(int x) {
  if (x == Pr[x]) return x;
  return Pr[x] = ata(Pr[x]);
}
void uni(int a, int b) {
  a = ata(a);
  b = ata(b);
  if (a == b) return;
  Pr[b] = a;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) Pr[i] = i;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    E[a].push_back(b);
    p[i] = {a, b};
  }
  Q.push(k);
  vis[k] = 1;
  while (!Q.empty()) {
    int nd = Q.front();
    Q.pop();
    for (auto i : E[nd]) {
      if (vis[i]) continue;
      vis[i] = 1;
      Q.push(i);
    }
  }
  vector<pair<int, int> > arr;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    int vis2[5010];
    for (int h = 1; h <= n; h++) vis2[h] = vis[h];
    Q.push(i);
    vis2[i] = 1;
    int ans = 0;
    while (!Q.empty()) {
      ans++;
      int nd = Q.front();
      Q.pop();
      for (auto h : E[nd]) {
        if (vis2[h]) continue;
        vis2[h] = 1;
        Q.push(h);
      }
    }
    arr.push_back({ans, i});
  }
  sort(arr.begin(), arr.end());
  reverse(arr.begin(), arr.end());
  int ans = 0;
  for (auto i : arr) {
    if (vis[i.second]) continue;
    ans++;
    Q.push(i.second);
    vis[i.second] = 1;
    while (!Q.empty()) {
      int nd = Q.front();
      Q.pop();
      for (auto h : E[nd]) {
        if (vis[h]) continue;
        vis[h] = 1;
        Q.push(h);
      }
    }
  }
  cout << ans;
}
