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


public class A {

	static int source;
	public static void main(String[] args) {
	
		FastScanner s = new FastScanner();
		int n = s.nextInt();
		int m = s.nextInt();
		 source = s.nextInt();
		
		int[] from = new int[m];
		int[] to = new int[m];
		int p = 0;
		for(int i=0;i<m;i++)
		{
			int u = s.nextInt()-1;
			int v = s.nextInt()-1;
			from[p] = u;
			to[p] = v;
			p++;
		}
		
		scc pk = new scc(from,to,n,m);
		
	}
	static class scc
	{
		int[][] G;
		int[][] GR;
		int[] stack;
		int[] SCC;
		static int scc=0;
		boolean[] visit;
		int sp = 0;
		int n;
		
		scc(int[] from , int[] to, int n, int m)
		{
			this.n = n;
			SCC = new int[n];
			stack = new int[n];
			visit = new boolean[n];
			G = make2DAdj(from, to, n, m);
			GR = transpose2DGraph(from, to, n, m);
			util();
		}
		
		void dfs(int u)
		{
			visit[u] = true;
			for(int v : G[u])
			{
				if(!visit[v])
				{
					dfs(v);
				}
			}
			stack[sp++] = u;
		}
		
		
		void kosaraju()
		{
			for(int i=0;i<n;i++)
				if(!visit[i])
					dfs(i);
			
			Arrays.fill(visit,false);
			for(int i=sp-1;i>=0;i--)
			{
				int pop = stack[i];
				if(!visit[pop])
				{
					scc++;
					SCC[pop] = scc;
					DFS(pop);
				}
			}
		}
		
		
		void DFS(int u)
		{
			visit[u] = true;
			for(int v:GR[u])
			{
				if(!visit[v])
				{
					SCC[v] = scc;
					DFS(v);
				}
			}
		}
		
		static int[][] transpose2DGraph(int[] from, int[] to, int n, int m)
		{
			return make2DAdj(to,from,n,m);
		}
		
		static int[][] make2DAdj(int[] from , int[] to, int n, int m)
		{
			int[][] g = new int[n][];
			int[] freq = new int[n];
			
			for(int i=0;i<m;i++)
			{
				freq[from[i]]++;
			}
			for(int i=0;i<n;i++)
				g[i] = new int[freq[i]];
			
			for(int i=0;i<m;i++)
			{
				g[from[i]][--freq[from[i]]] = to[i]; 
			}
	
			return g;
		}
		int[][] condense()
		{
			int[][] gScc= new int[scc+1][];
			int[] degreeScc= new int[scc+1];
			for(int i=0;i<n;i++)
				degreeScc[SCC[i]]+=G[i].length;
			for(int i=0;i<=scc;i++)
				gScc[i]= new int[degreeScc[i]];
			
			for(int i=0;i<n;i++)
			{
				for(int j :G[i])
				{
					gScc[SCC[i]][--degreeScc[SCC[i]]]=SCC[j];
				}
			}
		    
			int m=scc+1;
		    for(int i = 0;i < m;i++)
		    {
					Arrays.sort(gScc[i]);
					int jp = 0;
					for(int j = 0;j < gScc[i].length;j++){
						if((j == 0 || gScc[i][j] != gScc[i][j-1]) && gScc[i][j] != i){
							gScc[i][jp++] = gScc[i][j];
						}
					}
					gScc[i] = Arrays.copyOf(gScc[i], jp);
			}
			return gScc;
		}

		void util()
		{
			kosaraju();
			
			int[][] gScc = condense();
			
			int[] outdeg = new int[scc+1];
			for(int i=1;i<=scc;i++)
			{
				for(int v:gScc[i])
					outdeg[v]++;
			}
			int ans = 0;
			for(int i=1;i<=scc;i++)
				if(outdeg[i]==0&&SCC[source-1]!=i)
					ans++;
			System.out.println(ans);
		}
		
	}

static class FastScanner {
		
	    private InputStream mIs;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner() {
			this(System.in);
		}

		public FastScanner(InputStream is) {
			mIs = is;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = mIs.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		
		}	

	}

}
