#C11301. Treasure Hunt in the Park

    ID: 40603 Type: Default 1000ms 256MiB

Treasure Hunt in the Park

Treasure Hunt in the Park

Rahul is on a treasure hunt in a park consisting of N zones and M bidirectional paths. The zones are labeled from 1 to N. Rahul begins his journey at zone 1 and moves across the zones using a breadth-first search (BFS) strategy. Some zones contain treasures. The list of treasure zones is given, and Rahul stops moving as soon as he reaches any one of them.

Your task is to determine the zone where Rahul collects the treasure. If no treasure zone is reachable from zone 1, output -1.

The input obeys the following constraints: $1 \le N \le 10^5$, $1 \le M \le 10^5$, and edges describe a simple undirected graph.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains two integers N and M, representing the number of zones and the number of bidirectional paths.
  • The second line contains a single integer K, the number of zones that contain treasures.
  • The third line contains K distinct integers, each representing a treasure zone. If K is 0, this line will be empty.
  • The next M lines each contain two integers u and v indicating that there is a bidirectional path between zone u and zone v.

You may assume that the graph does not necessarily connect every zone to zone 1.

outputFormat

Output a single integer to standard output (stdout): the zone number where Rahul collects the treasure by following the BFS order. If no treasure zone is reachable from zone 1, output -1.

## sample
5 4
1
3
1 2
2 3
2 4
4 5
3