#include <bits/stdc++.h>
using namespace std;
const int M = 50005;
stack<int> s1;
vector<int> vec1[M];
int in[M], out[M], dfn[M], low[M], v[M], cnt, scnt, n, m, blong[M], siz[M];
void tarjan(int u) {
  s1.push(u);
  dfn[u] = low[u] = ++cnt;
  v[u] = 1;
  for (int i = 0; i < vec1[u].size(); i++) {
    int c = vec1[u][i];
    if (!dfn[c]) {
      tarjan(c);
      low[u] = min(low[u], low[c]);
    } else if (v[c])
      low[u] = min(low[u], dfn[c]);
  }
  if (dfn[u] == low[u]) {
    scnt++;
    while (!s1.empty()) {
      int c = s1.top();
      s1.pop();
      v[c] = 0;
      blong[c] = scnt;
      if (u == c) break;
    }
  }
}
int main() {
  int a, b, c, d, e, i, j, s;
  while (cin >> n) {
    cin >> m;
    cin >> s;
    cnt = 0;
    scnt = 0;
    memset(in, 0, sizeof(in));
    memset(out, 0, sizeof(out));
    memset(dfn, 0, sizeof(dfn));
    memset(low, 0, sizeof(low));
    memset(v, 0, sizeof(v));
    memset(siz, 0, sizeof(siz));
    while (!s1.empty()) {
      s1.pop();
    }
    for (i = 0; i < M; i++) {
      vec1[i].clear();
    }
    for (i = 1; i <= m; i++) {
      cin >> a >> b;
      vec1[a].push_back(b);
    }
    for (i = 1; i <= n; i++) {
      if (!dfn[i]) {
        tarjan(i);
      }
    }
    for (i = 1; i <= n; i++) {
      siz[blong[i]]++;
      for (j = 0; j < vec1[i].size(); j++) {
        c = vec1[i][j];
        if (blong[i] != blong[c]) {
          ++in[blong[c]];
          ++out[blong[i]];
        }
      }
    }
    int ans = 0, anst = 0;
    for (i = 1; i <= scnt; i++) {
      if (in[i] == 0) {
        anst++;
      }
    }
    if (in[blong[s]] == 0) {
      anst--;
    }
    cout << anst << endl;
  }
  return 0;
}
