Bausffs, known as the Killable Demon, was a fearless tactician who thrived on taking risks. He had a unique playstyle: he deliberately placed himself in difficult positions where every move could result in either great reward or crushing loss. His goal was simple — always come out with more gold than his opponent, no matter the odds.
But even Bausffs had limits.
That's where we come in. We are the Unkillable Demon eternal, analytical, and all-seeing. We know every decision that could be made in the game. We know their outcomes, the relation between them, and the true value they offer.
Each decision $$$i$$$ is characterized by an integer:
$$$$$$ D_i = (\text{Amount of Gold that Bausffs gains}) - (\text{Amount of Gold that Bausffs' enemy gains}) $$$$$$
Some decisions depend on others. That is, there exist some pair $$$(A, B)$$$ such that Bausffs cannot make decision $$$A$$$ unless he has already made decision $$$B$$$. Decisions can only be made once and, if necessary, several decisions can be made simultaneously.
Bausffs, eager to win and outplay his enemy, comes to us for help.
"Tell me," he says, "what is the maximum gold advantage I can gain if I choose my decisions wisely?"
And we, the Unkillable Demon, must answer.
The first line of input contains two integers $$$N$$$ and $$$M$$$ $$$\left(1 \leq N \leq 200, 1 \leq M \leq \frac{n(n-1)}{2}\right)$$$, representing the number of decisions and the number of relations, respectively.
The second line contain $$$N$$$ integers $$$D_i$$$ $$$(-1000 \leq D_i \leq 1000)$$$ separated by a space indicating the true value of that decision.
Each of the next M lines contains two integers separated by a space, $$$u_{i}$$$, $$$v_{i}$$$ $$$(1 \leq u_{i}, v_{i} \leq N)$$$ indicating that taking decision $$$u_{i}$$$ is a requirement for taking decision $$$v_{i}$$$.
Print a single line — The maximum gold advantage the Killable Demon can obtain.
6 4-10 -10 22 -3 5 11 32 33 44 5
5