# 3397. Dual Core CPU

As more and more computers are equipped with dual core CPU, SetagLilb, the Chief Technology Officer of TinySoft Corporation, decided to update their famous product - SWODNIW.

The routine consists of $N$ modules, and each of them should run in a certain core. The costs for all the routines to execute on two cores has been estimated. Let’s define them as $A_i$ and $B_i$. Meanwhile, $M$ pairs of modules need to do some data-exchange. If they are running on the same core, then the cost of this action can be ignored. Otherwise, some extra cost are needed. You should arrange wisely to minimize the total cost.

### 输入格式

There are two integers in the first line of input data, $N$ and $M$ $(1 \le N \le 20~000, 1 \le M \le 200~000)$.

The next $N$ lines, each contains two integer, $A_i$ and $B_i$ $(1 \le A_i, B_i \le 1~000)$.

In the following $M$ lines, each contains three integers: $a, b, w$ $(1 \le a, b \le N, a \neq b, 1 \le w \le 1~000)$. We guarantee no $a,b$ appears twice. The meaning is that if module $a$ and module $b$ don’t execute on the same core, you should pay extra $w$ dollars for the data-exchange between them.

### 输出格式

Output only one integer, the minimum total cost.

### 样例

Input
3 1
1 10
2 10
10 3
2 3 1000

Output
13


6 人解决，7 人已尝试。

6 份提交通过，共有 49 份提交。

6.9 EMB 奖励。