#include <bits/stdc++.h>
using namespace std;
vector<int> a[5003], b;
int vis[5003];
set<int> res;
int n, m, s, x, y;
void dfs(int u, int k) {
  vis[u] = k;
  for (int i = 0; i < a[u].size(); i++) {
    if (vis[a[u][i]] != k) dfs(a[u][i], k);
  }
}
int main() {
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    if (y != s) a[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i, i);
  }
  for (int i = 1; i <= n; i++) {
    res.insert(vis[i]);
  }
  cout << res.size() - 1;
  return 0;
}
