#include <bits/stdc++.h>
using namespace std;
int start;
void dfs(int par, int node, int vis[], vector<int> v[], int vis1[]) {
  vis[node] = par;
  vis1[node] = 1;
  for (int i = 0; i < v[node].size(); i++) {
    if (vis1[v[node][i]] == 0) dfs(par, v[node][i], vis, v, vis1);
  }
}
int main() {
  int n, m;
  cin >> n >> m >> start;
  vector<int> v[n + 1];
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    v[l].push_back(r);
  }
  int vis[n + 1], count = 0, vis1[n + 1];
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    memset(vis1, 0, sizeof(vis1));
    if (vis[i] == 0) dfs(i, i, vis, v, vis1);
  }
  memset(vis1, 0, sizeof(vis1));
  dfs(start, start, vis, v, vis1);
  map<int, int> map;
  for (int i = 1; i <= n; i++) {
    if (vis1[i] == 0) map[vis[i]]++;
  }
  cout << map.size();
  return 0;
}
