There are n cities and m roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way.

What is the minimum number of new roads that need to be built to make all the cities reachable from the capital?

New roads will also be one-way.

Input

The first line of input consists of three integers n, m and s (1 ≤ n ≤ 5000, 0 ≤ m ≤ 5000, 1 ≤ s ≤ n) — the number of cities, the number of roads and the index of the capital. Cities are indexed from 1 to n.

The following m lines contain roads: road i is given as a pair of cities u_i, v_i (1 ≤ u_i, v_i ≤ n, u_i ≠ v_i). For each pair of cities (u, v), there can be at most one road from u to v. Roads in opposite directions between a pair of cities are allowed (i.e. from u to v and from v to u).

Output

Print one integer — the minimum number of extra roads needed to make all the cities reachable from city s. If all the cities are already reachable from s, print 0.

Examples

Input

9 9 1
1 2
1 3
2 3
1 5
5 6
6 1
1 8
9 8
7 1


Output

3


Input

5 4 5
1 2
2 3
3 4
4 1


Output

1

Note

The first example is illustrated by the following:

<image>

For example, you can add roads (6, 4), (7, 9), (1, 7) to make all the cities reachable from s = 1.

The second example is illustrated by the following:

<image>

In this example, you can add any one of the roads (5, 1), (5, 2), (5, 3), (5, 4) to make all the cities reachable from s = 5.
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
long long bigmod(long long a, long long b) {
  if (b == 0) return 1;
  long long ret = bigmod(a, b / 2);
  return ret * ret % 1000000007 * (b % 2 ? a : 1) % 1000000007;
}
using namespace std;
pair<int, int> p[5010];
int n, m, k;
queue<int> Q;
int vis[5010], Pr[5010];
vector<int> E[5010];
int ata(int x) {
  if (x == Pr[x]) return x;
  return Pr[x] = ata(Pr[x]);
}
void uni(int a, int b) {
  a = ata(a);
  b = ata(b);
  if (a == b) return;
  Pr[b] = a;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) Pr[i] = i;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    E[a].push_back(b);
    p[i] = {a, b};
  }
  Q.push(k);
  vis[k] = 1;
  while (!Q.empty()) {
    int nd = Q.front();
    Q.pop();
    for (auto i : E[nd]) {
      if (vis[i]) continue;
      vis[i] = 1;
      Q.push(i);
    }
  }
  vector<pair<int, int> > arr;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    int vis2[5010];
    for (int h = 1; h <= n; h++) vis2[h] = vis[h];
    Q.push(i);
    vis2[i] = 1;
    int ans = 0;
    while (!Q.empty()) {
      ans++;
      int nd = Q.front();
      Q.pop();
      for (auto h : E[nd]) {
        if (vis2[h]) continue;
        vis2[h] = 1;
        Q.push(h);
      }
    }
    arr.push_back({ans, i});
  }
  sort(arr.begin(), arr.end());
  reverse(arr.begin(), arr.end());
  int ans = 0;
  for (auto i : arr) {
    if (vis[i.second]) continue;
    ans++;
    Q.push(i.second);
    vis[i.second] = 1;
    while (!Q.empty()) {
      int nd = Q.front();
      Q.pop();
      for (auto h : E[nd]) {
        if (vis[h]) continue;
        vis[h] = 1;
        Q.push(h);
      }
    }
  }
  cout << ans;
}
