Horror List

No attempts yetTime limit1sMemory limit128 MB

Problem

A cinema hosts a surprise screening: a small group gathers in a room and streams one random movie from a large collection. The trouble is that some people end up watching terrible movies and are deeply disappointed.

To prevent this, when a group enters the room they type in a horror list — the bad movies that no one in the group ever wants to see. This list differs from group to group.

You also have a database telling you which movies are directly similar to which. Assume that a movie similar to a bad movie is almost as bad. Formally, the Horror Index (HI) of a movie is defined as follows:

  • $HI = 0$ if the movie is on the horror list. (This rule overrides the others.)
  • $HI = Q + 1$ if the worst (i.e. lowest-HI) directly similar movie has $HI = Q$.
  • $HI = +\infty$ if the movie is not connected to any bad movie at all (directly or indirectly).

Input

The first line contains three integers $N$, $H$, $L$ ($1 \le H < N \le 1000$, $0 \le L \le 10000$), where $N$ is the number of movies (each identified by an ID from $0$ to $N-1$), $H$ is the number of movies on the horror list, and $L$ is the number of similarity relations in the database.

The second line contains $H$ distinct space-separated integers $x_i$ ($0 \le x_i < N$), the IDs of the movies on the horror list.

Each of the following $L$ lines contains two space-separated integers $a_i$, $b_i$ ($0 \le a_i < b_i < N$), meaning the movie with ID $a_i$ is similar to the movie with ID $b_i$ (and vice versa).

Output

Output the ID of the best movie, i.e. the one with the highest Horror Index. If several movies tie, output the one with the smallest ID.