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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            int m = in.ni();
            int s = in.ni() - 1;
            List<GraphUtil.Edge>[] g = in.readEdgesGraph(n, m, false);
            boolean[] reachable = new boolean[n];
            int[] stack = new int[n + m];
            int sti = 0;
            stack[sti++] = s;
            reachable[s] = true;
            while (sti > 0) {
                int v = stack[--sti];
                for (GraphUtil.Edge edge : g[v]) {
                    int to = edge.to;
                    if (!reachable[to]) {
                        stack[sti++] = to;
                        reachable[to] = true;
                    }
                }
            }
            G graph = new G(g);
            G gc = graph.condense();
            int[] incoming = new int[n];
            Arrays.fill(incoming, -1);
            for (int i = 0; i < n; i++) {
                if (gc.adj[i] != null && !reachable[i]) {
                    incoming[i]++;
                    for (GraphUtil.Edge edge : gc.adj[i]) {
                        if (!reachable[edge.to])
                            incoming[edge.to]++;
                    }
                }
            }
            int ans = 0;
            for (int inc : incoming) {
                if (inc == 0)
                    ans++;
            }
            out.println(ans);


        }

    }

    static class GraphUtil {
        public static class Edge {
            public int from;
            public int to;
            public int id;

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

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

        }

    }

    static class G {
        public List<GraphUtil.Edge>[] adj;

        public G(List<GraphUtil.Edge>[] g) {
            adj = g;
        }

        public G condense() {
            List<List<Integer>> sccs = new SCC().scc();
            int n = adj.length;
            int[] remap = new int[n];
            for (int i = 0; i < n; i++) {
                remap[i] = i;
            }
            for (List<Integer> scc : sccs) {
                int head = -1;
                for (int v : scc) {
                    if (head == -1)
                        head = v;
                    else {
                        remap[v] = head;
                    }
                }
            }
            List<GraphUtil.Edge>[] res = new List[n];
            for (int i = 0; i < n; i++) {
                if (remap[i] == i)
                    res[i] = new ArrayList<>(); // todo: null - condensed
            }
            for (int i = 0; i < n; i++) {
                for (GraphUtil.Edge edge : adj[i]) {
                    int to = edge.to;
                    if (remap[to] != remap[i]) {
                        res[remap[i]].add(new GraphUtil.Edge(remap[i], remap[to], edge.id));
                    }
                }
            }
            for (int i = 0; i < n; i++) {
                if (remap[i] != i)
                    continue;
                List<GraphUtil.Edge> edges = res[i];
                edges.sort(Comparator.comparingInt(e -> e.to));
                List<GraphUtil.Edge> list = new LinkedList<>();
                GraphUtil.Edge prev = null;
                for (GraphUtil.Edge edge : edges) {
                    if (prev == null || prev.to != edge.to) {
                        list.add(edge);
                        prev = edge;
                    }
                }
                res[i] = list;
            }
            return new G(res);
        }

        class SCC {
            int time;
            int[] lowlink;
            boolean[] used;
            List<Integer> stack;
            List<List<Integer>> components;

            public List<List<Integer>> scc() {
                int n = adj.length;
                lowlink = new int[n];
                used = new boolean[n];
                stack = new ArrayList<Integer>();//todo:
                components = new ArrayList<List<Integer>>();//todo:

                for (int u = 0; u < n; u++)
                    if (!used[u])
                        dfs(u);

                return components;
            }

            void dfs(int u) {
                lowlink[u] = time++;
                used[u] = true;
                stack.add(u);
                boolean isComponentRoot = true;

                for (GraphUtil.Edge e : adj[u]) {
                    int v = e.to;
                    if (!used[v])
                        dfs(v);
                    if (lowlink[u] > lowlink[v]) {
                        lowlink[u] = lowlink[v];
                        isComponentRoot = false;
                    }
                }

                if (isComponentRoot) {
                    List<Integer> component = new ArrayList<Integer>();
                    while (true) {
                        int k = stack.remove(stack.size() - 1);
                        component.add(k);
                        lowlink[k] = Integer.MAX_VALUE;
                        if (k == u)
                            break;
                    }
                    components.add(component);
                }
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public List<GraphUtil.Edge>[] readEdgesGraph(int n, int m, boolean bidirected) {
            List<GraphUtil.Edge>[] g = new List[n];
            for (int i = 0; i < n; i++) {
                g[i] = new LinkedList<>();
            }
            for (int i = 0; i < m; i++) {
                int u = ni() - 1;
                int v = ni() - 1;
                g[u].add(new GraphUtil.Edge(u, v, i));
                if (bidirected)
                    g[v].add(new GraphUtil.Edge(v, u, i));
            }

            return g;
        }

    }
}

