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>
const long long int mod = 9999999999999983;
long long int primes[6] = {1125899906842597, 1495921043, 1005985879,
                           1495921043,       1005985879, 1495921043};
using namespace std;
vector<long long int> adj[2000009];
long long int parent[2000009];
long long int vis[5009];
long long int visited[5009];
long long int level[2000009];
long long int dist[2000009];
long long int dp[2000009];
long long int arr[2000009];
long long int brr[2000009];
long long int crr[2000009];
long long int hashing[2000009];
long long int ar[509][509];
long long int br[509][509];
long long int cr[509][509];
long long int indeg[5009];
long long int counter;
void dfs(long long int val) {
  long long int i;
  vis[val] = 1;
  for (i = 0; i < adj[val].size(); i++) {
    if (vis[adj[val][i]] == 0) {
      dfs(adj[val][i]);
    }
  }
}
void Dfs(long long int val) {
  long long int i;
  visited[val] = 1;
  counter++;
  for (i = 0; i < adj[val].size(); i++) {
    if (visited[adj[val][i]] == 0) {
      Dfs(adj[val][i]);
    }
  }
}
int main() {
  int start_s = clock();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<pair<long long int, long long int> > vect, vt, vct;
  vector<long long int>::iterator itt;
  set<long long int> st;
  set<long long int>::iterator itr;
  map<long long int, long long int> mp;
  map<long long int, long long int>::iterator it;
  string str;
  long long int i, j, k, n, m, q, t, a, b, c,
      maxi = INT_MIN, mini = INT_MAX, sum = 0, ans = 0, res = 0, val = 0,
      ans1 = 0, ans2 = 0, rem = 0, diff = 0, cnt = 0, l, r, flag = 0, e, index,
      val1 = 0, val2 = 0, x, y, z, h = 0, u, v, mid, len, tot, fl = 0;
  cin >> n >> m >> k;
  for (i = 1; i <= m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    indeg[v]++;
  }
  dfs(k);
  for (i = 1; i <= n; i++) {
    if (indeg[i] == 0 && i != k && vis[i] == 0) {
      cnt++;
      dfs(i);
    }
  }
  for (i = 1; i <= n; i++) {
    if (vis[i] == 0 && indeg[i] != 0) {
      counter = 0;
      memset(visited, 0, sizeof(visited));
      Dfs(i);
      vect.push_back({counter, i});
    }
  }
  sort(vect.rbegin(), vect.rend());
  for (i = 0; i < vect.size(); i++) {
    if (vis[vect[i].second] == 0) {
      cnt++;
      dfs(vect[i].second);
    }
  }
  cout << cnt;
}
