**291 人解决**，381 人已尝试。

**393 份提交通过**，共有 1436 份提交。

**2.7** EMB 奖励。

**单点时限: **2.0 sec

**内存限制: **256 MB

Partychen is working as system administrator and is planning to establish a new network in his company. There will be N hubs in the company, they can be connected to each other using cables. Since each worker of the company must have access to the whole network, each hub must be accessible by cables from any other hub (with possibly some intermediate hubs).

Since cables of different types are available and shorter ones are cheaper, it is necessary to make such a plan of hub connection, that the cost is minimal. partychen will provide you all necessary information about possible hub connections. You are to help partychen to find the way to connect hubs so that all above conditions are satisfied.

The first line of the input contains two integer numbers: N - the number of hubs in the network (2 <= N <= 1000) and M - the number of possible hub connections (1 <= M <= 15000). All hubs are numbered from 1 to N. The following M lines contain information about possible connections - the numbers of two hubs, which can be connected and the cable cost required to connect them. cost is a positive integer number that does not exceed 106. There will always be at least one way to connect all hubs.

Output the minimize cost of your hub connection plan.

Input

4 6 1 2 1 1 3 1 1 4 2 2 3 1 3 4 1 2 4 1

Output

3 Hint We can build net from 1 to 2 to 3 to 4,then we get the cost is 3.Of course you can get 3 by other way.

**291 人解决**，381 人已尝试。

**393 份提交通过**，共有 1436 份提交。

**2.7** EMB 奖励。

题目标签