#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 1e14;
const double pi = acos(-1.0);
vector<int> E[maxn];
bool vis[maxn], tvis[maxn];
void dfs1(int x) {
  vis[x] = true;
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (vis[v] == true) continue;
    dfs1(v);
  }
  return;
}
void dfs2(int x) {
  vis[x] = 1;
  for (int i = 0; i < E[x].size(); i++) {
    int v = E[x][i];
    if (vis[v]) continue;
    if (tvis[v]) tvis[v] = false;
    dfs2(v);
  }
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, s;
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    E[x].push_back(y);
  }
  dfs1(s);
  for (int i = 1; i <= n; i++)
    if (vis[i] == false) tvis[i] = true;
  for (int i = 1; i <= n; i++) {
    if (tvis[i] == true) {
      memset(vis, false, sizeof(vis));
      dfs2(i);
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (tvis[i] == true) ans++;
  }
  cout << ans;
  return 0;
}
