시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB56373477.273%

문제

An undirected graph is given, each of its nodes associated with a positive integer value. Given a threshold, nodes of the graph are divided into two groups: one consisting of the nodes with values less than or equal to the threshold, and the other consisting of the rest of the nodes. Now, consider a subgraph of the original graph obtained by removing all the edges connecting two nodes belonging to different groups. When both of the node groups are non-empty, the resultant subgraph is disconnected, whether or not the given graph is connected.

Then a number of new edges are added to the subgraph to make it connected, but these edges must connect nodes in different groups, and each node can be incident with at most one new edge. The threshold is called feasible if neither of the groups is empty and the subgraph can be made connected by adding some new edges.

Your task is to find the minimum feasible threshold.

입력

The input consists of a single test case of the following format.

n m
l1 . . . ln
x1 y1
.
.
.
xm ym

The first line contains two integers n (2 ≤ n ≤ 105) and m (0 ≤ m ≤ min(105, n(n−1)/2)), the numbers of the nodes and the edges, respectively, of the graph. Nodes are numbered 1 through n. The second line contains n integers li (1 ≤ li ≤ 109), meaning that the value associated with the node i is li. Each of the following m lines contains two integers xj and yj (1 ≤ xj < yj ≤ n), meaning that an edge connects the nodes xj and yj. At most one edge exists between any two nodes.

출력

Output the minimum feasible threshold value. Output -1 if no threshold values are feasible.

예제 입력 1

4 2
10 20 30 40
1 2
3 4

예제 출력 1

20

예제 입력 2

2 1
3 5
1 2

예제 출력 2

3

예제 입력 3

3 0
9 2 8

예제 출력 3

-1

예제 입력 4

4 6
5 5 5 5
1 2
1 3
1 4
2 3
2 4
3 4

예제 출력 4

-1

예제 입력 5

7 6
3 1 4 1 5 9 2
2 3
3 5
5 6
1 4
1 7
4 7

예제 출력 5

2