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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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 {
        int[] start;
        int[] next;
        int[] edge;
        boolean[] mrk;
        boolean[] mrkExtended;
        int N = 5000;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int s = in.nextInt();

            start = new int[n + 1];
            Arrays.fill(start, -1);
            next = new int[2 * N + 1];
            edge = new int[2 * N + 1];

            for (int i = 0; i < m; i++) {
                int x = in.nextInt();
                int y = in.nextInt();

                next[i] = start[x];
                edge[i] = y;
                start[x] = i;
            }

            mrk = new boolean[n + 1];
            mrkExtended = new boolean[n + 1];
            Arrays.fill(mrk, false);
            Arrays.fill(mrkExtended, false);
            mrkEdges(s);
            List<Pair> ext = new ArrayList<>();
            for (int i = 1; i <= n; i++) {
                if (!mrk[i]) {
                    Arrays.fill(mrkExtended, false);
                    int x = mrkExtendedEdges(i);
                    ext.add(new Pair(i, x));
                }
            }

            ext.sort((x, y) -> y.second - x.second);
            int id = m;
            int ans = 0;
            for (Pair p : ext) {
                if (!mrk[p.first]) {
                    next[id] = start[s];
                    edge[id] = p.first;
                    start[s] = id;
                    id++;
                    mrkEdges(s);
                    ans++;
                }
            }
            out.print(ans);
        }

        private void mrkEdges(int u) {
            mrk[u] = true;
            for (int i = start[u]; i != -1; i = next[i]) {
                int v = edge[i];
                if (!mrk[v]) mrkEdges(v);
            }
        }

        private int mrkExtendedEdges(int u) {
            mrkExtended[u] = true;
            int ret = 1;
            for (int i = start[u]; i != -1; i = next[i]) {
                int v = edge[i];
                if (!mrk[v] && !mrkExtended[v]) ret += mrkExtendedEdges(v);
            }
            return ret;
        }

        private class Pair {
            int first;
            int second;

            public Pair(int first, int second) {
                this.first = first;
                this.second = second;
            }

        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

    }
}

