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.*;
import java.io.*;
 
public class Main {
    static boolean checked[];
    static int[] cnt;
    static ArrayList<ArrayList<Integer>> map;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int cap = sc.nextInt()-1;
        ArrayList<Edge> arr = new ArrayList<>();
        SCC scc = new SCC(n);
        cnt = new int[n];
        for(int i = 0; i < m; i++){
            int f = sc.nextInt()-1;
            int t = sc.nextInt()-1;
            scc.addEdge(f,t);
            arr.add(new Edge(f,t));
        }
        scc.build();
        map = new ArrayList<>();
        for(int i = 0; i < n; i++){
            map.add(new ArrayList<>());
        }
        checked = new boolean[n];
        int[] cnt = new int[n];
        ArrayList<HashSet<Integer>> chk = new ArrayList<>();
        for(int i = 0; i < n; i++){
            chk.add(new HashSet<>());
        }
        for(Edge e : arr){
            int f = scc.id(e.f);
            int t = scc.id(e.t);
            if(f == t || chk.get(f).contains(t)) continue;
            map.get(f).add(t);
            chk.get(f).add(t);
            cnt[t]++;
        }
        int ans = 0;
        checked[scc.id(cap)] = true;
        dfs(scc.id(cap));
        HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
        for(int i = 0; i < n; i++){
            int id = scc.id(i);
            //pw.println(id + " " + i);
            if(checked[id]) continue;
            hm.put(id,cnt[id]);
        }
        while(hm.size() > 0){
            HashMap<Integer,Integer> tmp = new HashMap<>();
            for(Map.Entry<Integer,Integer> e : hm.entrySet()){
                tmp.put(e.getKey(),e.getValue());
                //pw.println(e.getKey() + " " + e.getValue());
            }
            for(Map.Entry<Integer,Integer> e : tmp.entrySet()){
                if(checked[e.getKey()]){
                    hm.remove(e.getKey());
                }
                if(e.getValue() == 0){
                    ans++;
                    checked[e.getKey()] = true;
                    dfs(e.getKey());
                    hm.remove(e.getKey());
                }
            }
        }
        pw.println(ans);
        pw.flush();
    }
    
    static void dfs(int now){
        for(int next : map.get(now)){
            if(!checked[next]){
                checked[next] = true;
                dfs(next);
            }
            cnt[next]--;
        }
    }
    
    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
    }
}

class Edge{
    int f,t;
    public Edge(int f, int t){
        this.f = f;
        this.t = t;
    }
}

/**
 * @verified https://atcoder.jp/contests/practice2/tasks/practice2_g
 */
class SCC {

    static class Edge {
        int from, to;
        public Edge(int from, int to) {
            this.from = from; this.to = to;
        }
    }

    final int n;
    int m;
    final java.util.ArrayList<Edge> unorderedEdges;
    final int[] start;
    final int[] ids;
    boolean hasBuilt = false;

    public SCC(int n) {
        this.n = n;
        this.unorderedEdges = new java.util.ArrayList<>();
        this.start = new int[n + 1];
        this.ids = new int[n];
    }

    public void addEdge(int from, int to) {
        unorderedEdges.add(new Edge(from, to));
        start[from + 1]++;
        this.m++;
    }

    public int id(int i) {
        if (!hasBuilt) {
            throw new UnsupportedOperationException(
                "Graph hasn't been built."
            );
        }
        return ids[i];
    }
    
    public int[][] build() {
        for (int i = 1; i <= n; i++) {
            start[i] += start[i - 1];
        }
        Edge[] orderedEdges = new Edge[m];
        int[] count = new int[n + 1];
        System.arraycopy(start, 0, count, 0, n + 1);
        for (Edge e : unorderedEdges) {
            orderedEdges[count[e.from]++] = e;
        }
        int nowOrd = 0;
        int groupNum = 0;
        int k = 0;
        // parent
        int[] par = new int[n];
        int[] vis = new int[n];
        int[] low = new int[n];
        int[] ord = new int[n];
        java.util.Arrays.fill(ord, -1);
        // u = lower32(stack[i]) : visiting vertex
        // j = upper32(stack[i]) : jth child
        long[] stack = new long[n];
        // size of stack
        int ptr = 0;
        // non-recursional DFS
        for (int i = 0; i < n; i++) {
            if (ord[i] >= 0) continue;
            par[i] = -1;
            // vertex i, 0th child.
            stack[ptr++] = 0l << 32 | i;
            // stack is not empty
            while (ptr > 0) {
                // last element
                long p = stack[--ptr];
                // vertex
                int u = (int) (p & 0xffff_ffffl);
                // jth child
                int j = (int) (p >>> 32);
                if (j == 0) { // first visit
                    low[u] = ord[u] = nowOrd++;
                    vis[k++] = u;
                }
                if (start[u] + j < count[u]) { // there are more children
                    // jth child
                    int to = orderedEdges[start[u] + j].to;
                    // incr children counter
                    stack[ptr++] += 1l << 32;
                    if (ord[to] == -1) { // new vertex
                        stack[ptr++] = 0l << 32 | to;
                        par[to] = u;
                    } else { // backward edge
                        low[u] = Math.min(low[u], ord[to]);
                    }
                } else { // no more children (leaving)
                    while (j --> 0) {
                        int to = orderedEdges[start[u] + j].to;
                        // update lowlink
                        if (par[to] == u) low[u] = Math.min(low[u], low[to]);
                    }
                    if (low[u] == ord[u]) { // root of a component
                        while (true) { // gathering verticies
                            int v = vis[--k];
                            ord[v] = n;
                            ids[v] = groupNum;
                            if (v == u) break;
                        }
                        groupNum++; // incr the number of components
                    }
                }
            }
        }
        for (int i = 0; i < n; i++) {
            ids[i] = groupNum - 1 - ids[i];
        }
        
        int[] counts = new int[groupNum];
        for (int x : ids) counts[x]++;
        int[][] groups = new int[groupNum][];
        for (int i = 0; i < groupNum; i++) {
            groups[i] = new int[counts[i]];
        }
        for (int i = 0; i < n; i++) {
            int cmp = ids[i];
            groups[cmp][--counts[cmp]] = i;
        }
        hasBuilt = true;
        return groups;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}
