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

public class Source {
    private static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;
        public FastScanner(InputStream inputStream){
            br = new BufferedReader(new InputStreamReader(inputStream));
        }
        public String next() {
            while (st == null || !st.hasMoreTokens()){
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException ignored){}
            }
            return st.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    private static long lcm(long a, long b) {
        return Math.abs(a * b) / gcd(a, b);
    }

    private static boolean dfs(ArrayList<Integer>g[], int v, int p, int []color) {
        if (p == -1) {
            color[v] = 1;
        }
        else {
            if (color[p] == 1) {
                color[v] = 2;
            }
            else {
                color[v] = 1;
            }
        }
        for (int i = 0; i < g[v].size(); i++) {
            int j = g[v].get(i);
            if (color[j] > 0 && color[j] == color[v]) {
                return false;
            } else if (color[j] == 0) {
                if (!dfs(g, j, v, color))
                    return false;
            }
        }
        return true;
    }

    private static boolean isPrime(long num) {
        if (num < 2) return false;
        if (num == 2) return true;
        if (num % 2 == 0) return false;
        for (int i = 3; i * i <= num; i += 2)
            if (num % i == 0) return false;
        return true;
    }

    private static List<Long> ps(long n) {
        List<Long> result = new ArrayList<>();
        if (n < 2) {
            return result;
        }
        if (isPrime(n)) {
            result.add(n);
            return result;
        }
        long p [] = new long[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113};
        for (int i = 0; i < p.length; i++) {
            if (n % p[i] == 0) {
                result.add(p[i]);
                result.addAll(ps (n / p[i]));
                return result;
            }
        }
        return result;
    }

    private static List<Long> lol(long n) {
        List<Long>ps = ps(n);
        Set<Long>result = new HashSet<>(ps);
        boolean bitmask [] = new boolean[ps.size() + 1];
        while(true) {
            int i = bitmask.length - 1;
            while (bitmask[i]) i--;
            if (i == 0) break;
            bitmask[i] = true;
            for (int j = i + 1; j < bitmask.length; j++) {
                bitmask[j] = false;
            }
            long c = 1;
            for (int j = 1; j < bitmask.length; j++) {
                if (bitmask[j]) {
                    c *= ps.get(j - 1);
                }
            }
            result.add(c);
        }
        result.add(1L);
        result.add(n);
        List<Long>t = new ArrayList<>(result);
        Collections.sort(t);
        return t;
    }

    private static boolean[] visited;
    private static ArrayList<Integer>g[];
    private static ArrayList<Integer>sorted = new ArrayList<>();

    private static void dfs(int v) {
        visited[v] = true;
        for (int i = 0; i < g[v].size(); i++) {
            int j = g[v].get(i);
            if (!visited[j]) {
                dfs(j);
            }
        }
    }

    private static void dfs2(int v) {
        visited[v] = true;
        for (int i = 0; i < g[v].size(); i++) {
            int j = g[v].get(i);
            if (!visited[j]) {
                dfs2(j);
            }
        }
        sorted.add(v);
    }

    public static void main(String [] args) throws Exception {
        FastScanner scanner = new FastScanner(System.in);
        PrintWriter printer = new PrintWriter(System.out);
        //scanner = new FastScanner(new FileInputStream("input.txt"));
        //printer = new PrintWriter(new FileOutputStream("output.txt"));
        int n = scanner.nextInt(), m = scanner.nextInt(), start = scanner.nextInt() - 1;
        g = new ArrayList[n];
        visited = new boolean[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int x = scanner.nextInt() - 1, y = scanner.nextInt() - 1;
            g[x].add(y);
        }
        for (int i = 0; i < n; i++) {
            if(!visited[i]) {
                dfs2(i);
            }
        }
        Collections.reverse(sorted);
        //printer.println(sorted);
        for (int i = 0; i < n; i++) {
            visited[i] = false;
        }
        dfs(start);
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int j = sorted.get(i);
            if (!visited[j]) {
                ans++;
                dfs(j);
            }
        }
        printer.println(ans);
        printer.close();
    }
}