#include <bits/stdc++.h>
using namespace std;
int n, m, s;
vector<int> DSK[5005];
void ReadData() {
  int u, v;
  cin >> n >> m >> s;
  while (m--) {
    cin >> u >> v;
    DSK[u].push_back(v);
  }
}
bool visit[5005];
void F_DFS(int u) {
  visit[u] = true;
  for (int i = 0; i < DSK[u].size(); i++) {
    int w = DSK[u][i];
    if (!visit[w]) F_DFS(w);
  }
}
int cnt = 0;
int Low[5005];
int Num[5005];
stack<int> S;
int res = 0;
int com[5005];
void S_DFS(int u) {
  Low[u] = Num[u] = ++cnt;
  S.push(u);
  for (int i = 0; i < DSK[u].size(); i++) {
    int w = DSK[u][i];
    if (visit[w]) continue;
    if (Num[w])
      Low[u] = min(Low[u], Num[w]);
    else {
      S_DFS(w);
      Low[u] = min(Low[w], Low[u]);
    }
  }
  if (Num[u] == Low[u]) {
    res++;
    com[u] = res;
    int v;
    do {
      v = S.top();
      S.pop();
      com[v] = res;
      Num[v] = Low[v] = INT_MAX;
    } while (u != v);
  }
}
bool vao[5005];
void process() {
  F_DFS(s);
  for (int i = 1; i <= n; i++) {
    if (!Num[i] && !visit[i]) {
      S_DFS(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < DSK[i].size(); j++) {
      int w = DSK[i][j];
      if (com[i] != com[w]) vao[com[w]] = true;
    }
  }
  int ans = 0;
  for (int i = 1; i <= res; i++) {
    if (!vao[i]) ans++;
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ReadData();
  process();
}
