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.
import java.util.*;


public class capital {

	
	static int[] vis;
	static int[] cmp;
	static int[] qcmp;

	static int[] indeg;

	static int cnt = 1;
	static int Ans=0;
	static Stack<Integer> exit;
	static List<Integer>[] g;
	static List<Integer>[] rg;
	static List<Integer>[] cg;

	public static void dfs(int a){
		//System.out.println(a);

		vis[a]=1;
		
		for(Integer z : g[a]){
			if(vis[z]==0)
				dfs(z);
		}
		exit.push(a);	
	}
	public static void dfs2(int a){
		//System.out.println(a);

		cmp[a]=cnt;
		
		for(Integer z : rg[a]){
			if(cmp[z]==0)
				dfs2(z);
		}
	}
	public static void dfs3(int a){
		//System.out.println(a);

		qcmp[a]=1;
	//	System.out.println(a);
		for(Integer z : cg[a]){
			if(qcmp[z]==0)
				dfs3(z);
		}
	}
	
	public static void main(String[] args) 
	{
		int q,i,j,k,l,r,step=0,m,n,ans=-1000000009,w,x,y,a,f=1,b,c,d,e,s;

		Scanner cin = new Scanner(System.in);
		
		n = cin.nextInt();
		m = cin.nextInt();
		s = cin.nextInt();
		
		vis = new int[n+1];
		indeg = new int[n+1];
		cmp = new int[n+1];
		qcmp = new int[n+1];

		exit = new Stack();
	    g = new List[n+1];
	    rg = new List[n+1];
	    cg = new List[n+1];
	    
	    for (i = 1; i <= n; i++) {
	      g[i] = new ArrayList<>();
	      rg[i] = new ArrayList<>();
	      cg[i] = new ArrayList<>();
	    }
		//ArrayList<Integer>[] ls = new ArrayList[k];

	  	for(i=0;i<m;i++){
	  		x = cin.nextInt();
	  		y = cin.nextInt();
	  		g[x].add(y);
	  		rg[y].add(x);
		  }
	  	//Kosaraju's Algorithm
	  	for(i=1;i<=n;i++){
	  		if(vis[i]==0)
	  		dfs(i);
		  }
	  	
	  	//no. of SCC's
	  	for(i=1;i<=n;i++){
	  		
	  		if(cmp[exit.peek()]==0)
	  		{	
	  			dfs2(exit.pop());
	  			cnt++;
	  		}
	  		else
	  			exit.pop();
	  		
		  }
	  	
	  	for(i=1;i<=n;i++){
	  		for(Integer z:g[i]){
	  			if(cmp[i]!=cmp[z]){
	  				cg[cmp[i]].add(cmp[z]);
	  				indeg[cmp[z]]++;
	  			}
	  		}
	  	}
	  
	  	dfs3(cmp[s]);
	  	
	  	for(i=1;i<cnt;i++){
	  		if(qcmp[i]==0 && indeg[i]==0)
	  		Ans++;
	  		
	  	}
	  System.out.println(Ans);
	}
	
}