Travel Tax

No attempts yetTime limit3sMemory limit256 MB

Problem

The ruler of the kingdom of Byteotia, following a worldwide trend, has decided to tax everything that can be taxed. The most recently introduced levy is the so-called travel tax, which must be paid by everyone who moves around the country.

Every road in Byteotia has an assigned tax rate. When you pass through a city during a journey, you must pay a tax at that city's office equal to the maximum of the rate on the road by which you entered the city and the rate on the road by which you leave it. You also pay in the starting city and in the destination city of the journey; there, since only one road is used, the tax is computed from that single road alone.

Your friend Byteasar is setting out on a journey from city 11 to city nn. Help him plan a route so that he pays as little tax as possible.

Input

The first line contains two integers nn and mm (2n1000002 \le n \le 100\,000, 1m2000001 \le m \le 200\,000), the number of cities and the number of roads in Byteotia. Cities are numbered from 11 to nn.

Each of the next mm lines describes one road: the ii-th such line contains three integers aia_i, bib_i, cic_i (1ai,bin1 \le a_i, b_i \le n, aibia_i \ne b_i, 1ci10000001 \le c_i \le 1\,000\,000). They mean that cities aia_i and bib_i are connected by a two-way road whose tax rate is cic_i bytalers. There is at most one road between any pair of cities.

Output

Print a single integer: the minimum cost of the journey (in bytalers) from city 11 to city nn. You may assume that a sequence of roads connecting these two cities always exists.

Hint

For example, suppose the roads are {1,2}\{1,2\} with rate 55, {1,3}\{1,3\} with rate 22, {2,3}\{2,3\} with rate 11, {2,4}\{2,4\} with rate 44, and {3,4}\{3,4\} with rate 88. The optimal route runs through cities 13241 \to 3 \to 2 \to 4. The taxes paid at these cities are 22, max(2,1)=2\max(2, 1) = 2, max(1,4)=4\max(1, 4) = 4, and 44, which add up to 1212.