#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
const int maxn = 6001;
vector<int> g[maxn];
int n, m, s;
int x, y;
vector<pair<int, int> > lst;
int vis[maxn], vis_cur[maxn], mark[maxn];
void mark_dfs(int x) {
  mark[x] = 1;
  for (auto &v : g[x]) {
    if (mark[v]) continue;
    mark_dfs(v);
  }
}
int cnt = 0;
void dfs(int x) {
  vis[x] = 1;
  cnt++;
  for (auto &v : g[x]) {
    if (mark[v] | vis[v]) continue;
    dfs(v);
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
  }
  mark_dfs(s);
  for (int i = 1; i <= n; i++) {
    if (mark[i]) continue;
    for (int j = 1; j <= n; j++) vis[j] = 0;
    cnt = 0;
    dfs(i);
    lst.push_back(pair<int, int>(cnt, i));
  }
  sort(lst.begin(), lst.end());
  reverse(lst.begin(), lst.end());
  int ans = 0;
  for (int i = 0; i < lst.size(); i++) {
    int x = lst[i].second;
    if (mark[x]) continue;
    mark_dfs(x);
    ans++;
  }
  cout << ans << endl;
}
