Ferries

No attempts yetTime limit2sMemory limit512 MB

Problem

Kang the penguin lives on a group of NN Antarctic islands numbered 11 to NN. His house is on island 11. He has a cold today, so he wants to visit the veterinarian who works on island NN.

He would normally swim, but with the cold he plans to take ferries instead. There are MM ferries, numbered 11 to MM. Ferry ii carries passengers from island AiA_i to island BiB_i for CiC_i dollars, and it runs in that direction only. At most one ferry runs from one island to another island, and a ferry may charge 00 dollars. Kang wants to reach island NN as cheaply as possible.

Unfortunately for the penguin, the captains have started a money making scheme today. They know Kang plans to ride from island 11 to island NN, so they agreed to make his trip as expensive as they can. Captains whose ferries depart from the same island may swap destinations among themselves. Their contracts fix the fare of each ferry, so a fare stays with its ferry even after its destination changes. Suppose ferries 11, 22 and 33 all depart from island 11, they go to islands 22, 33 and 44, and they charge 1010, 2020 and 3030 dollars. The captains of ferry 11 and ferry 22 may trade destinations, after which ferry 11 goes to island 33 and still charges 1010 dollars, while ferry 22 goes to island 22 and still charges 2020 dollars.

The captains announce the final destinations before Kang boards any ferry, and they cannot change them afterwards. Kang knows what the captains are planning, but he does not know the destinations before he leaves his house. He wants the smallest amount of money that is certain to be enough for the trip. In other words, find the cost of Kang's cheapest route to island NN when the captains arrange the destinations so that this cheapest route costs as much as possible.

Input

Your program reads from standard input. The first line contains two integers NN and MM. Each of the next MM lines contains three integers AiA_i, BiB_i and CiC_i, describing one ferry. A route from island 11 to island NN always exists.

Output

Your program writes one integer to standard output, the minimum number of dollars Kang needs to reach his doctor.