#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v, next;
} E[5010], nE[5010];
int p[5010], eid;
int np[5010], neid;
void init() {
  memset(p, -1, sizeof(p));
  eid = 0;
}
void ninit() {
  memset(np, -1, sizeof(np));
  neid = 0;
}
void insert(int u, int v) {
  E[eid].v = v;
  E[eid].next = p[u];
  p[u] = eid++;
}
void ninsert(int u, int v) {
  nE[neid].v = v;
  nE[neid].next = np[u];
  np[u] = neid++;
}
int n, m, s;
int dfn[5010], low[5010], belong[5010], cnt = 0, times = 0;
stack<int> sta;
void dfs(int u) {
  dfn[u] = low[u] = ++times;
  sta.push(u);
  for (int i = p[u]; i != -1; i = E[i].next) {
    int v = E[i].v;
    if (dfn[v] == 0) {
      dfs(v);
      low[u] = min(low[u], low[v]);
    } else if (!belong[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (low[u] == dfn[u]) {
    ++cnt;
    while (true) {
      int x = sta.top();
      sta.pop();
      belong[x] = cnt;
      if (x == u) {
        break;
      }
    }
  }
}
bool vis[5010];
int _back[5010];
void DFS(int now) {
  vis[now] = true;
  for (int i = np[now]; i != -1; i = nE[i].next) {
    int v = nE[i].v;
    if (vis[v] == false) {
      DFS(v);
    }
  }
}
int main() {
  cin >> n >> m >> s;
  init();
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    insert(u, v);
  }
  memset(dfn, 0, sizeof(dfn));
  times = cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (dfn[i] == 0) {
      dfs(i);
    }
  }
  ninit();
  for (int u = 1; u <= n; u++) {
    for (int i = p[u]; i != -1; i = E[i].next) {
      int v = E[i].v;
      if (belong[u] != belong[v]) {
        ninsert(belong[u], belong[v]);
        _back[belong[v]]++;
      }
    }
  }
  memset(vis, false, sizeof(vis));
  int ans = 0;
  DFS(belong[s]);
  for (int i = 1; i <= cnt; i++) {
    if (vis[i] == false && _back[i] == 0) {
      ans++;
      DFS(i);
    }
  }
  for (int i = 1; i <= cnt; i++) {
    if (vis[i] == false) {
      ans++;
      DFS(i);
    }
  }
  cout << ans << endl;
  return 0;
}
