Year Many people left Earth and built some cities on Mars.
Currently there are N cities, some of which are connected by narrow one-way roads.
The president of Mars has decided to build police stations throughout the Mars.
Given the cost of building police stations at each city, we cannot build them at all cities,
due to the financial deficit. The only requirement is that every city must be reachable from
some police station by roads. They expect the cost of all stations as low as possible.

The first line for each case contains two integers n, m(0 < n <= 5,000. 0 < m <= 100,000),

the number of cities and roads. The follows n lines each contains two integers, i, c

( 0 < i <= n . 0 < c <=10,000 ), c represents the cost of building a police station in city i ,

The next m lines each contains two integers u and v ( 0 < u, v <= n), indicating that there is

a road form u to v .

For each test case, print the minimum cost of stations

FZU 2006 ICPC Qualification Round I