#include <bits/stdc++.h>
template <typename T>
void MACRO_VAR_Scan(T& t) {
  std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
  std::cin >> first;
  MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
  t.resize(n);
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First& first, Rest&... rest) {
  first.resize(n);
  MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T>
void MACRO_VEC_ROW_Scan(int p, T& t) {
  std::cin >> t[p];
}
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First& first, Rest&... rest) {
  std::cin >> first[p];
  MACRO_VEC_ROW_Scan(p, rest...);
}
template <typename T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <typename T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
void CHECKTIME(std::function<void()> f) {
  auto start = std::chrono::system_clock::now();
  f();
  auto end = std::chrono::system_clock::now();
  auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start))
                 .count();
  std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n";
}
template <class T>
std::vector<std::vector<T>> VV(int n, int m, T init = T()) {
  return std::vector<std::vector<T>>(n, std::vector<T>(m, init));
}
template <typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<ll, ll>;
using PAIRLL = std::pair<ll, ll>;
constexpr ll INFINT = 1 << 30;
constexpr ll INFINT_LIM = (1LL << 31) - 1;
constexpr ll INFLL = 1LL << 60;
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);
constexpr double EPS = 1e-9;
constexpr ll MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template <class T, size_t N>
void FILL(T (&a)[N], const T& val) {
  for (auto& x : a) x = val;
}
template <class ARY, size_t N, size_t M, class T>
void FILL(ARY (&a)[N][M], const T& val) {
  for (auto& b : a) FILL(b, val);
}
template <class T>
void FILL(std::vector<T>& a, const T& val) {
  for (auto& x : a) x = val;
}
template <class ARY, class T>
void FILL(std::vector<std::vector<ARY>>& a, const T& val) {
  for (auto& b : a) FILL(b, val);
}
struct StronglyConnectedComponent {
  ll n;
  std::vector<std::vector<ll>> g, rg;
  std::vector<bool> used;
  std::vector<ll> vs;
  std::vector<ll> cmp;
  std::vector<std::vector<ll>> pre;
  StronglyConnectedComponent(ll n) : n(n), g(n), rg(n), used(n), cmp(n) {}
  ll operator[](ll id) { return cmp[id]; }
  void addEdge(ll from, ll to) {
    g[from].emplace_back(to);
    rg[to].emplace_back(from);
  }
  void dfs(ll v) {
    used[v] = true;
    for (size_t i = 0; i < g[v].size(); ++i) {
      if (!used[g[v][i]]) dfs(g[v][i]);
    }
    vs.emplace_back(v);
  }
  void rdfs(ll v, ll k) {
    used[v] = true;
    cmp[v] = k;
    for (size_t i = 0; i < rg[v].size(); ++i) {
      if (!used[rg[v][i]]) rdfs(rg[v][i], k);
    }
  }
  ll scc() {
    used.assign(n, false);
    vs.clear();
    for (size_t v = 0; v < n; ++v) {
      if (!used[v]) dfs(v);
    }
    used.assign(n, false);
    ll k = 0;
    for (signed i = vs.size() - 1; i >= 0; --i) {
      if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
  }
  bool same(ll u, ll v) { return cmp[u] == cmp[v]; }
  std::vector<std::vector<ll>> getDAG() {
    ll N = scc();
    std::vector<std::vector<ll>> res(N);
    std::vector<std::set<ll>> set(N);
    pre.resize(N);
    for (ll i = 0; i < ll(n); ++i) {
      set[cmp[i]].insert(i);
    }
    for (ll i = 0; i < ll(N); ++i) {
      std::set<ll> out;
      for (const auto& v : set[i]) {
        pre[i].emplace_back(v);
        for (const auto& to : g[v]) {
          out.insert(cmp[to]);
        }
      }
      for (const auto& to : out) {
        if (i != to) res[i].emplace_back(to);
      }
    }
    return res;
  }
};
signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ;
  ll n, m, s;
  MACRO_VAR_Scan(n, m, s);
  ;
  std::vector<ll> u, v;
  MACRO_VEC_ROW_Init(m, u, v);
  for (ll i = 0; i < m; ++i) {
    MACRO_VEC_ROW_Scan(i, u, v);
  };
  StronglyConnectedComponent scc(n);
  for (ll i = 0; i < ll(m); ++i) {
    --u[i];
    --v[i];
    scc.addEdge(u[i], v[i]);
  }
  --s;
  auto g = scc.getDAG();
  ll sz = g.size();
  std::vector<ll> in(sz, 0);
  for (ll i = 0; i < ll(sz); ++i) {
    for (auto& to : g[i]) {
      ++in[to];
    }
  }
  std::vector<bool> used(sz, false);
  ll ans = 0;
  auto bfs = [&](ll start) {
    used[start] = true;
    std::queue<ll> que({start});
    while (!que.empty()) {
      ll now = que.front();
      que.pop();
      for (auto& to : g[now]) {
        if (used[to]) continue;
        used[to] = true;
        que.push(to);
      }
    }
  };
  bfs(scc.cmp[s]);
  for (ll i = 0; i < ll(sz); ++i) {
    if (used[i]) continue;
    if (in[i] == 0) {
      ++ans;
      bfs(i);
    }
  }
  for (ll i = 0; i < ll(sz); ++i) {
    if (used[i]) continue;
    ++ans;
    bfs(i);
  }
  std::cout << (ans);
  std::cout << "\n";
  ;
  return 0;
}
