#include <bits/stdc++.h>
using namespace std;
void Open() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int dx[]{1, -1, 0, 0, 1, 1, -1, -1};
int dy[]{0, 0, 1, -1, 1, -1, 1, -1};
const int OO = 0x3f3f3f3f;
int n, m, s;
vector<vector<int>> g, gg;
bool p = 1;
bool pp[20002];
bool ppp[20002];
long long ans;
int en;
void dfs(int node) {
  if (pp[node]) return;
  pp[node] = 1;
  for (auto it : g[node]) dfs(it);
}
int dfs2(int node) {
  ppp[node] = 1;
  for (auto it : gg[node])
    if (ppp[it] == 0)
      return dfs2(it);
    else {
      for (auto ip : gg[it]) {
        if (ppp[ip] == 0) {
          return dfs2(ip);
        }
      }
    }
  return node;
}
void test_case() {
  cin >> n >> m >> s;
  g = vector<vector<int>>(n + 1);
  gg = vector<vector<int>>(n + 1);
  int x, y;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    gg[y].push_back(x);
  }
  dfs(s);
  for (int i = 1; i <= n; i++) {
    if (!pp[i]) {
      int x = dfs2(i);
      dfs(x);
      ans++;
    }
  }
  cout << ans << "\n";
}
int main() {
  Open();
  int t = 1;
  while (t--) {
    test_case();
  }
}
