Consider the map of a country, with n cities (numbered between 0 and n−1) and m unidirectional roads that connect them. Each road has a certain length. We want to go from city 0 to city 1. As we travel with people prone to get carsick, and we do not want to stop halfway to stretch our legs, we want to follow the route such that the longest road we take is as short as possible. That is, if the route uses k roads, with lengths ℓ1, ⋯, ℓk, and ℓ = max(ℓ1, ⋯, ℓk), we want ℓ to be as small as possible.
Input
The input consists in several cases. Each case begins with n and m, followed by m triplets x y ℓ, with x ≠ y, indicating a road that goes from x to y of length ℓ. Assume 2 ≤ n ≤ 104, 1 ≤ m ≤ 10n, that there is at most one road from x to y in this order, that the lengths are between 1 and 105, and that there is always a route between 0 and 1.
Output
For each case, write the maximum length of the roads of the best possible route.
The second line of the example of output corresponds to the route 0 → 4 → 2 → 1, which has a road (the 0 → 4) of maximum length 80.
Hint
Consider a variant of Dijkstra’s algorithm.
Input
2 2 0 1 100000 1 0 42 5 6 0 1 90 0 4 80 4 1 60 0 2 100 2 1 60 4 2 70
Output
100000 80