#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long INF = 1e12;
const int MOD = 1e9 + 7;
const unsigned long long BIT_FLAG_0 = (1 << 0);
const unsigned long long BIT_FLAG_1 = (1 << 1);
const unsigned long long BIT_FLAG_2 = (1 << 2);
const unsigned long long BIT_FLAG_3 = (1 << 3);
const unsigned long long BIT_FLAG_4 = (1 << 4);
const unsigned long long BIT_FLAG_5 = (1 << 5);
const unsigned long long BIT_FLAG_6 = (1 << 6);
const unsigned long long BIT_FLAG_7 = (1 << 7);
const long long dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const long long Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1},
                Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
void print() { cout << "\n"; }
template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << "\n";
}
template <class T>
void print(set<T> &set) {
  for (auto &a : set) {
    cout << a << " ";
  }
  cout << "\n";
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto &vec : df) {
    print(vec);
  }
}
long long power(long long x, long long n) {
  long long ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
}
long long comb(long long n, long long k) {
  vector<vector<long long>> v(n + 1, vector<long long>(n + 1, 0));
  for (long long i = 0; i < (long long)((v).size()); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (long long k = 1; k < (long long)((v).size()); k++) {
    for (long long j = 1; j < k; j++) {
      v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
    }
  }
  return v[n][k];
}
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
__attribute__((constructor)) void faster_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
class SCC {
 private:
  const long long V;
  vector<vector<long long>> G;
  vector<long long> ord, low;
  stack<long long> st;
  void dfs(const long long u, long long &tm) {
    ord[u] = low[u] = tm++, st.push(u);
    for (long long v : G[u]) {
      if (ord[v] < 0) {
        dfs(v, tm);
        low[u] = min(low[u], low[v]);
      } else if (cmp[v] < 0) {
        low[u] = min(low[u], ord[v]);
      }
    }
    if (ord[u] == low[u]) {
      while (true) {
        const long long v = st.top();
        st.pop();
        cmp[v] = cnt;
        if (v == u) break;
      }
      ++cnt;
    }
  }

 public:
  vector<vector<long long>> graph;
  vector<long long> cmp;
  long long cnt;
  SCC(const long long node_size)
      : V(node_size), G(V), ord(V, -1), low(V), cmp(V, -1), cnt(0) {}
  void add_edge(const long long from, const long long to) {
    G[from].push_back(to);
  }
  long long solve() {
    long long tm = 0;
    for (long long i = 0; i < V; ++i) {
      if (ord[i] < 0) dfs(i, tm);
    }
    for (long long i = 0; i < V; ++i) cmp[i] = cnt - 1 - cmp[i];
    return cnt;
  }
  void make_graph() {
    graph.resize(cnt);
    for (long long i = 0; i < V; ++i) {
      for (long long j : G[i]) {
        if (cmp[i] != cmp[j]) {
          graph[cmp[i]].push_back(cmp[j]);
        }
      }
    }
  }
};
signed main() {
  long long n, m, s;
  cin >> n >> m >> s;
  s--;
  SCC scc(n);
  for (long long i = 0; i < (long long)(m); i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    scc.add_edge(a, b);
  }
  scc.solve();
  scc.make_graph();
  vector<vector<long long>> graph = scc.graph;
  vector<bool> accessed((long long)((graph).size()), false);
  for (auto i : graph) {
    for (auto j : i) {
      accessed[j] = true;
    }
  }
  auto s_belong = scc.cmp[s];
  long long cnt = 0;
  for (long long ni = 0; ni < (long long)((long long)((graph).size())); ni++) {
    if (ni == s_belong) {
      continue;
    }
    if (!accessed[ni]) {
      cnt++;
    }
  }
  print(cnt);
}
