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.ArrayList;
import java.util.Scanner;
import java.util.Stack;

public class Solution {

	static void sortDAG(int k, int[] v, ArrayList<Integer>[] G, Stack<Integer> stk, ArrayList<Integer>[] DAG, int[] vDAG) {
		v[k] = 1;
		
		for (int i : DAG[k]) {
			for (int j : G[i])
				if (v[vDAG[j]] == 0)
					sortDAG(vDAG[j], v, G, stk, DAG, vDAG);
		}
		
		stk.push(k);
	}
	
	static void DFS(int k, int[] v, ArrayList<Integer>[] G, ArrayList<Integer>[] DAG, int[] vDAG) {
		v[k] = 1;
		
		for (int i : DAG[k]) {
			for (int j : G[i])
				if (v[vDAG[j]] == 0)
					DFS(vDAG[j], v, G, DAG, vDAG);
		}
	}
	
	static void KS1(int k, int[] v, ArrayList<Integer>[] G, Stack<Integer> stk) {
		v[k] = 1;
		
		for (int vec : G[k]) {
			if (v[vec] == 0)
				KS1(vec, v, G, stk);
		}
		
		stk.push(k);
	}
	
	static void KS2(int k, int[] v, ArrayList<Integer>[] G, ArrayList<Integer> l) {
		v[k] = 1;
		l.add(k);
		for (int vec : G[k]) {
			if (v[vec] == 0)
				KS2(vec, v, G, l);
		}
	}
	
	public static void main(String[] args) {
		int n, m, s;
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		m = scanner.nextInt();
		s = scanner.nextInt();
		
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] G = new ArrayList[n+1];
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] GT = new ArrayList[n+1];
		
		for (int i = 0; i <= n; i++) {
			G[i] = new ArrayList<Integer>();
			GT[i] = new ArrayList<Integer>();
		}
		
		for (int i = 0; i < m; i++) {
			int a, b;
			a = scanner.nextInt();
			b = scanner.nextInt();
			
			G[a].add(b);
			GT[b].add(a);
		}
		
		Stack<Integer> stk = new Stack<>();
		
		int[] v = new int[n+1];
		int[] vDAG = new int[n+1];
		for (int i = 1; i <= n; i++)
			if (v[i] == 0)
				KS1(i, v, G, stk);
		
		for (int i = 1; i <= n; i++)
			v[i] = 0;
		
		ArrayList<Integer>[] DAG = new ArrayList[n+1];
		int nr = 0, source = 0;
		while (!stk.isEmpty()) 
			if (v[stk.peek()] == 0){
				nr++;
				DAG[nr] = new ArrayList<Integer>();
			
				KS2(stk.pop(), v, GT, DAG[nr]);
				
				for (int i : DAG[nr]) {
					vDAG[i] = nr;
					if (i == s)
						source = nr;
				}
			}
			else
				stk.pop();
		
		for (int i = 1; i <= n; i++)
			v[i] = 0;
		
		for (int i = 1; i <= nr; i++)
			if (v[i] == 0)
				sortDAG(i, v, G, stk, DAG, vDAG);
		
		for (int i = 1; i <= n; i++)
			v[i] = 0;
		
		DFS(source, v, G, DAG, vDAG);
		
		int add = 0;
		while (!stk.isEmpty())
			if (v[stk.peek()] == 0) {
				add++;
				G[s].add(DAG[stk.pop()].get(0));
				DFS(source, v, G, DAG, vDAG);
			}
			else
				stk.pop();
		System.out.println(add);
		scanner.close();
	}

}
