#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long inf = 1000000001;
const long long INF = 2e18;
const long long MOD = 1000000007;
const double pi = 3.14159265358979323846;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
vector<vector<int> > child(5010), parent(5010);
vector<int> color(5010, -1);
int n, m, s;
vector<int> roots, roots2;
void dfs1(int now, int col) {
  color[now] = col;
  for (long long i = 0; i < (long long)(child[now].size()); i++) {
    if (color[child[now][i]] < 0) {
      dfs1(child[now][i], col);
    }
  }
}
void dfs2(int now) {
  color[now] = -2;
  if (parent[now].size() == 0) {
    roots.push_back(now);
    return;
  }
  bool flag = true;
  for (long long i = 0; i < (long long)(parent[now].size()); i++) {
    if (color[parent[now][i]] == -1) {
      dfs2(parent[now][i]);
      flag = false;
    }
  }
  if (flag) {
    roots2.push_back(now);
  }
  return;
}
int main() {
  cin >> n >> m >> s;
  s--;
  for (long long i = 0; i < (long long)(m); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    child[u].push_back(v);
    parent[v].push_back(u);
  }
  dfs1(s, s);
  int ans = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    if (color[i] >= 0) {
      continue;
    }
    roots.clear();
    dfs2(i);
    ans += roots.size();
    for (long long j = 0; j < (long long)(roots.size()); j++) {
      dfs1(roots[j], roots[j]);
    }
  }
  for (long long i = 0; i < (long long)(roots2.size()); i++) {
    if (color[roots2[i]] < 0) {
      ans++;
      dfs1(roots2[i], roots2[i]);
    }
  }
  cout << ans << endl;
}
