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

public class Main {


    static int[] a;
    static int[] b;
    static int[] c;

    static int[] aa;
    static int[] bb;
    static int[] cc;



    //for tarjan
    static int[] dfn;//dfn意味着第几个访问到的  也意味着有没有访问过(== 0)
    static int[] low;
    static boolean[] inStack;
    static Stack<Integer> stack;
    static int deep;
    static int countOfPoint = 0;
    static int[] tarjanColor;

    //for bfs
    static int[] point;
    static boolean[] visited;

    static int[] indegree;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int s = in.nextInt();

        dfn = new int[n + 10];
        low = new int[n + 10];
        inStack = new boolean[n + 10];
        stack = new Stack<>();
        deep = 0;
        tarjanColor = new int[n + 10];

        a = new int[m + 10];
        b = new int[m + 10];
        c = new int[n + 10];

        int x, y;
        for (int i = 1; i <= m; i++) {
            x = in.nextInt();
            y = in.nextInt();
            a[i] = y;
            b[i] = c[x];
            c[x] = i;
        }


        for (int i = 1; i <= n; i++) {
            if (dfn[i] == 0) {
                tarjan(i);
            }
        }

//        for (int i = 1; i <= n; i++) {
//            System.out.println(tarjanColor[i]);
//        }

        //change point number to the number after tarjan.
        aa = new int[m + 10];
        bb = new int[m + 10];
        cc = new int[n + 10];

        int j, count = 0, to;
        for (int i = 1; i <= n; i++) {
            j = c[i];
            while (j != 0) {
                to = a[j];
                if (tarjanColor[to] != tarjanColor[i]) {
                    ++count;
                    aa[count] = tarjanColor[to];
                    bb[count] = cc[tarjanColor[i]];
                    cc[tarjanColor[i]] = count;
                }

                j = b[j];
            }
        }



//        for (int i = 1; i <= count; i++) {
//            System.out.println(aa[i] + "  " + bb[i] + "  " + cc[i]);
//        }


        indegree = new int[countOfPoint + 10];
        for (int i = 1; i <= countOfPoint; ++i) {
            j = cc[i];
            while (j != 0) {
                ++indegree[aa[j]];
                j = bb[j];
            }
        }

//        for (int i = 1; i <= countOfPoint; ++i) {
//            System.out.println(indegree[i]);
//        }

        int answer = 0;
        for (int i = 1; i <= countOfPoint; ++i) {
            if (indegree[i] == 0 && i != tarjanColor[s]) {
                ++answer;
            }
        }

        System.out.println(answer);
    }

    public static void tarjan(int from) {
        ++deep;
        dfn[from] = deep;
        low[from] = deep;
        inStack[from] = true;
        stack.push(from);

        int i = c[from];
        int to;
        while (i != 0) {
            to = a[i];
            if (dfn[to] == 0) {
                tarjan(to);
                low[from] = Math.min(low[to], low[from]);
            } else {
                if (inStack[to]) {
                    low[from] = Math.min(low[to], low[from]);
                }
            }
            i = b[i];
        }

        if (dfn[from] == low[from]) {
            countOfPoint++;
            while (stack.peek() != from) {
                tarjanColor[stack.peek()] = countOfPoint;
                inStack[stack.pop()] = false;
            }
            tarjanColor[from] = countOfPoint;
            inStack[stack.pop()] = false;
        }
    }

//    public static void bfs(int start) {
//        int l = 0;
//        int r = 0;
//        point[0] = start;
//        int i, to;
//
//        while (l <= r) {
//            i = c[point[l]];
//            while (i != 0) {
//                to = a[i];
//                point[++r] = to;
//                visited[to] = true;
//                i = b[i];
//            }
//            ++l;
//        }
//
//     }


}
