#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5050;
int n, m, s;
int u, v;
int fa[MAXN];
int vis[MAXN];
vector<int> G[MAXN];
set<int> res;
void dfs(int u, int f) {
  if (fa[u] == f) {
    return;
  }
  fa[u] = f;
  for (int i = 0; i < G[u].size(); i++) {
    dfs(G[u][i], f);
  }
}
int idx = 0;
bool check_circle(int u, bool isS) {
  printf("check_circle %d %d\n", u, isS);
  vis[u] = -1;
  for (int i = 0; i < G[u].size(); i++) {
    if (vis[G[u][i]] == -1) {
      if (isS) {
        printf("true\n");
        return true;
      } else {
        printf("false\n");
        return false;
      }
    } else {
      if (G[u][i] == s) {
        check_circle(G[u][i], true);
      } else {
        check_circle(G[u][i], false);
      }
      vis[G[u][i]] = 0;
    }
  }
  vis[u] = 0;
}
int main(void) {
  scanf("%d%d%d", &n, &m, &s);
  while (m--) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
  }
  dfs(s, s);
  for (int i = 1; i <= n; i++) {
    if (fa[i] == 0) {
      dfs(i, i);
    }
  }
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    if (fa[i] == s) {
      flag = 1;
    }
    res.insert(fa[i]);
  }
  printf("%d\n", res.size() - flag);
  return 0;
}
