Wells

On a tree where placing wells at a vertex counts for it and its direct neighbors, find the minimum number of wells so every village's demand is met.

Hard8TreeDynamic programmingGreedyDFSNo attempts yetTime limit2sMemory limit256 MB

Problem

Hyunsung wants to install wells in villages for African children who cannot drink as much water as they need.

Each village needs a different number of wells. Installing one well in village A counts as one well for village A and for every village connected to A directly by a road. You may install several wells in the same village.

For example, suppose village A is connected to B and to C, and villages A, B, and C need 5, 10, and 7 wells respectively. If you install 5 wells in village A, villages B and C also have 5 wells each counted toward their needs.

Hyunsung donates a lot, so he does not have much money. There are nn villages, village ii needs at least WiW_i wells (W1,W2,,WnW_1, W_2, \ldots, W_n), and there are mm roads between villages. Find the minimum total number of wells to install so that every village's requirement is met.

Input

The first line contains the number of villages nn (1n100,0001 \le n \le 100{,}000) and the number of roads mm (1m<100,0001 \le m < 100{,}000).

The second line contains the minimum number of wells each village needs, W1,W2,,WnW_1, W_2, \ldots, W_n (0Wi10,000,0000 \le W_i \le 10{,}000{,}000).

Each of the next mm lines describes a road with two village numbers aa and bb that the road connects. Villages are numbered from 11 to nn, and there is exactly one path between any two villages.

Output

Print the minimum number of wells to install on the first line.