#include <bits/stdc++.h>
using namespace std;
int N, M, second, cnt[(int)5000 + 7], ans;
vector<int> v[5005];
vector<pair<int, int> > vec;
bool done[(int)5000 + 7], vis[(int)5000 + 7];
void dfs(int n, bool type, int second) {
  if (type) done[n] = 1;
  vis[n] = 1;
  if (!done[n]) cnt[second]++;
  for (int i = 0; i < v[n].size(); i++) {
    int to = v[n][i];
    if (!vis[to]) dfs(to, type, second);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> second;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
  }
  dfs(second, 1, 0);
  for (int i = 1; i <= N; i++) {
    if (!done[i]) {
      memset(vis, 0, sizeof vis);
      dfs(i, 0, i);
      vec.push_back(make_pair(cnt[i], i));
    }
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < vec.size(); i++) {
    int n = vec[i].second;
    if (!done[n]) {
      memset(vis, 0, sizeof vis);
      dfs(n, 1, 0);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
