Airplane
문제
Benson the Rabbit wants to fly an airplane!
There are regions that Benson can fly in, numbered from to . For each region , there is a minimum altitude that Benson must fly at within the region due to terrain constraints.
Additionally, Benson can only fly between certain pairs of regions due to prevailing wind conditions and Benson’s lack of flying experience (he is a rabbit after all). There are such pairs numbered from to , and the -th pair and indicates that Benson can fly between regions and in both directions. It is always possible to travel from any region to all other regions using only the allowed pairs.
Initially, Benson is at region at height . He wants to travel to region , and to land he must end at height .
In a minute, Benson can choose to stay at his current region or travel to another region. In that same minute, his altitude can increase by , decrease by or remain the same. However, when Benson arrives at a region, his height must be at least the minimum altitude required for that region. What is the minimum time Benson needs to land at region ?
입력
The first line of input will contain spaced integers and , which represent the number of regions and the number of pairs of regions that Benson can fly between.
The next line contains spaced integers , representing the minimum required altitude at each region.
The next lines of input will contain spaced integers each. The -th of these lines contains and , indicating that Benson can fly between regions and in both directions.
출력
The output should contain one integer, the minimum time required to land at region .
예제
예제 1
3 2 0 2 0 1 2 2 3
4
예제 2
11 12 0 0 0 0 0 0 2 2 1 5 0 1 2 2 3 3 4 4 5 5 6 6 11 1 7 7 8 8 9 9 11 1 10 10 11
5