#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7f7f7f7f;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int n, m;
vector<int> vec[5005];
int vis[5005];
stack<int> s;
int visited[5005];
void topoSortUtil(int i) {
  visited[i] = true;
  for (int j = 0; j < vec[i].size(); j++) {
    int node = vec[i][j];
    if (!visited[node]) topoSortUtil(node);
  }
  s.push(i);
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < vec[u].size(); i++) {
    int v = vec[u][i];
    if (vis[v] == 0) {
      dfs(v);
    }
  }
  return;
}
void display() {
  int cnt = 0;
  while (!s.empty()) {
    int val = s.top();
    s.pop();
    if (vis[val] == 0) {
      dfs(val);
      cnt++;
    }
  }
  cout << cnt << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, s, x, y;
  cin >> n >> m >> s;
  vector<int> ans;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    vec[x].push_back(y);
  }
  dfs(s);
  for (int i = 1; i <= n; i++) {
  }
  int cnt = 0;
  memset(visited, 0, sizeof(visited));
  for (int i = 1; i <= n; i++) {
    if (visited[i] == 0) topoSortUtil(i);
  }
  display();
  return 0;
}
