Power Shortage

No attempts yetTime limit1sMemory limit256 MB

Problem

Seongjin is the mayor of a city, but the city is short on money and struggling with a power shortage. So he decides to turn off some of the streetlights that were originally lit on every road. Keeping a road's streetlights on costs money each day equal to the road's length in meters, so turning some off saves exactly that much money.

However, it is dangerous if traveling between two houses forces you to pass along a road whose lights are off. Therefore, for every pair of houses in the city, it must be possible to travel between them using only lit roads.

Find the maximum amount of money that can be saved while satisfying this condition.

Input

The input consists of several test cases.

The first line of each test case contains the number of houses $m$ and the number of roads $n$. ($1 \le m \le 200000$, $m - 1 \le n \le 200000$)

Each of the next $n$ lines describes a road with three integers $x$, $y$, $z$, meaning there is a bidirectional road between house $x$ and house $y$ whose length is $z$ meters. ($0 \le x, y < m$, $x \ne y$)

The city is always a connected graph; that is, for any two houses there exists a path between them. The sum of the lengths of all roads in the city is less than $2^{31}$ meters.

The last line of the input contains two zeros in place of $m$ and $n$; this line is not processed.

Output

For each test case, print on one line the maximum cost that can be saved.