This page is still under construction.

Parts of this page are still being built. What you see may change.

The Rural Postman

Time limit1sMemory limit128 MB

Summary
Start at village 1 and cover every road and village to maximize order-based village payments minus one euro per move.
Level

Medium5 of 10

Topics
Math, Graph, Implementation
Solved
No attempts yet

Problem

A rural postman must deliver mail to everyone in the region: the people living in the villages and those living along the roads that connect the villages.

Help him choose a route that drives along every road and visits every village at least once. In every case considered here, such a route is guaranteed to exist. Routes can differ in value, because the post office is paid differently depending on which route is taken, and it is the post office's profit (not the postman's) that matters.

Each village wants the postman to arrive as early as possible, so every village signs the following contract with the post office. Suppose village ii is the kk-th distinct village the postman reaches, meaning he had already visited k−1k-1 different villages before reaching village ii for the first time. If k≤w(i)k \le w(i), the village pays the post office w(i)−kw(i) - k euros. If k>w(i)k > w(i), the post office pays the village k−w(i)k - w(i) euros. On top of that, the post office pays the postman one euro for every drive between two consecutive villages on the route.

There are nn villages, numbered 11 to nn. The post office is in village 11, so the route must start in village 11. Exactly 22, 44, or 88 roads meet at each village. Two villages may be connected by several different roads, and a road may also return to the village it starts from.

Compute the maximum total profit, in euros, that the post office can achieve over all valid routes. If every route makes the post office lose money, report the smallest possible loss as a negative number.

Input

The first line contains two integers nn and mm separated by a single space: the number of villages nn (1≤n≤2001 \le n \le 200) and the number of roads mm.

Each of the next nn lines contains one positive integer. The value on line i+1i+1 is w(i)w(i) (1≤w(i)≤10001 \le w(i) \le 1000), the base amount village ii would pay the post office (adjusted by the contract described above).

Each of the next mm lines contains two integers separated by a single space: the numbers of the two villages joined by that road.

Output

Print one integer: the maximum total profit, in euros, that the post office can obtain. The value may be negative.

Hint

Examples2

  1. Example 1

    Input
    6 7
    1
    7
    4
    10
    20
    5
    2 4
    1 5
    2 1
    4 5
    3 6
    1 6
    1 3
    
    Expected output
    19
    
  2. Example 2

    Input
    1 1
    5
    1 1
    
    Expected output
    3