#include <bits/stdc++.h>
using namespace std;
const int tdh = 1e9 + 7;
long long ksm(long long a, long long b) {
  long long ans = 1;
  a %= tdh;
  while (b) {
    if (b & 1) ans = ans * a % tdh;
    a = (a * a) % tdh;
    b >>= 1;
  }
  return ans % tdh;
}
inline long long read() {
  long long x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}
int vis[5050];
int ru[5050];
vector<int> a[5050];
void work(int x) {
  int i, y;
  vis[x] = 1;
  for (i = 0; i < a[x].size(); i++) {
    y = a[x][i];
    if (vis[y] == 0) work(y);
  }
}
int u[5005], v[5005], h[5050];
void work2(int x, int z) {
  int i, y;
  vis[x] = z;
  for (i = 0; i < a[x].size(); i++) {
    y = a[x][i];
    if (vis[y] != 1 && vis[y] != z) work2(y, z);
  }
}
int main() {
  ios::sync_with_stdio(false);
  int n, m, s;
  int i, j, k;
  int ans = 0, cnt;
  cin >> n >> m >> s;
  for (i = 1; i <= m; i++) {
    cin >> u[i] >> v[i];
    a[u[i]].push_back(v[i]);
    ru[v[i]]++;
  }
  work(s);
  for (i = 1; i <= n; i++)
    if (i != s && ru[i] == 0) {
      ans++;
      work(i);
    }
  cnt = 1;
  for (i = 1; i <= n; i++)
    if (vis[i] == 0) {
      cnt++;
      work2(i, cnt);
    }
  h[1] = 1;
  for (i = 1; i <= n; i++) {
    h[vis[i]]++;
    if (h[vis[i]] == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}
