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.util.*;

public class MainClass
{
    static int n = 0;
    static int m = 0;
    static int s = 0;
    static List<Integer>[] adj;
    static boolean[] visited;
    static boolean[] auxVisited;
    static boolean[] helperVisited;
    static Game[] count;
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        n = in.nextInt();
        m = in.nextInt();
        s = in.nextInt() - 1;
        adj = new ArrayList[n];
        visited = new boolean[n];
        auxVisited = new boolean[n];
        count = new Game[n];
        for (int i=0;i<n;i++)   count[i] = new Game(1L, i);
        helperVisited = new boolean[n];
        for (int i=0;i<n;i++)   adj[i] = new ArrayList<>();
        for (int i=0;i<m;i++)   adj[in.nextInt() - 1].add(in.nextInt() - 1);

        explore(s);
        for (int i=0;i<n;i++)
        {
            if (!visited[i])
            {
                Arrays.fill(auxVisited, false);
                count[i].count = recur(i);
            }
        }
        Arrays.sort(count);
        int ans = 0;
        for (int i=0;i<n;i++)
        {
            int v = count[i].v;
            if (!visited[v] && !helperVisited[v])
            {
                ans ++;
                mark(v);
            }
        }
        System.out.println(ans);
    }
    public static void mark(int v)
    {
        helperVisited[v] = true;
        for (int u: adj[v]) if (!helperVisited[u] && !visited[u])   mark(u);
    }
    public static long recur(int v)
    {
        auxVisited[v] = true;
        long cc = 0L;
        for (int u: adj[v])
        {
            if (!visited[u] && !auxVisited[u])
            {
                cc += recur(u);
            }
        }
        return cc + 1L;
    }
    public static void explore(int v)
    {
        visited[v] = true;
        for (int u: adj[v]) if (!visited[u])    explore(u);
    }
}
class Game implements Comparable<Game>
{
    long count;
    int v;

    public Game(long count, int v)
    {
        this.count = count;
        this.v = v;
    }

    @Override
    public int compareTo(Game game)
    {
        if (this.count < game.count)
            return 1;
        else if (this.count > game.count)
            return -1;
        return 0;
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private final DataInputStream din;
    private final byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}