- Time limit: 1.00 s
- Memory limit: 128 MB
You are given information on the structure of the airport. Your task is to calculate the speed at which passengers can travel from the departure hall to the gate area.
The airport consists of corridors and checkpoints (security check, passport control, etc.). Each checkpoint comes with information on how many passengers can pass through it per minute.
There's no limit on how many people can pass through corridors per minute.
Input
The first input line has two integers and : the number of checkpoints and the number of corridors. The checkpoints are numbered . Checkpoint 1 is the departure hall and checkpoint is the gate area.
Then there are integers : how many passengers can pass through the checkpoint per minute. The number means that there is no limit. There are never any restrictions in the departure hall or in the gate area.
Finally, the input includes lines, each of which describes one corridor. Each line has two integers and : there is a corridor between checkpoints and . All corridors are one-way.
Output
Your program should print one integer: the maximum possible flow of passengers from the departure hall to the gate area.
You can assume that the answer is not infinite.
Limits
Example
Input:
7 8 -1 40 50 10 -1 20 -1 1 2 1 3 3 4 3 5 2 6 4 7 5 7 6 7
Output:
70