railroad

Time limit: 0.7s Memory limit: 64MB Input: Output:

Task

There are NN cities and MM bidirectional railways connecting cities aia_i and bib_i with a travel time of cic_i minutes. There is also a train that connects city 00 with city N1N-1, this train will always take the only shortest path between the two cities.

However, the train only passes through some cities and the mayors of the cities it doesn't pass through are angry.

To please the mayors, you can upgrade a single railway to high-speed railway, which will reduce the travel time by 11 minute for each euro spent. Of course, the travel time must be strictly positive after the upgrade.

You want to upgrade a railway so that the new shortest path between city 00 and city N1N-1 always passes to at least a city that wasn't passed by the train before.
In the new railway network there may be many shortest paths, however the original one must not be one of them.

What is the minimum amount of money you need to spend to achieve this?

Input

The first line contains the integers NN (2N1052 \le N \le 10^5) and MM (1M31051 \le M \le 3 * 10^5), the number of cities and the number of railways.

The following MM lines contains three integers aia_i, bib_i and cic_i representing a bidirectional railway between aia_i and bib_i with a travel time of cic_i minutes. (0ai,biN10 \le a_i, b_i \le N - 1), (1ci1091 \le c_i \le 10^9).

It is guaranteed that the shortest path between 0 and N1N-1 is unique.

For tests worth 3535 points, (N1000N \le 1000, M2000M \le 2000).

For tests worth 3030 more points, N=MN = M, and each city has exactly two railways.

Example 1

stdin

4 5
0 1 20
0 2 60
1 2 5
2 3 20
1 3 20

stdout

6

Example 2

stdin

4 5
0 1 5
0 2 10
1 2 10
2 3 10
1 3 5

stdout

-1

Output

You need to write a single line with an integer: the minimum amount of money you need to spend so that the new shortest path between city 00 and city N1N-1 always passes through a new city. If it is not possible to achieve this, you need to write 1-1.

Notes

In the first sample case, it is possible to upgrade the railway between cities 22 and 33 so that the new shortest path passes through city 22.




In the second sample case, it is not possible to upgrade a railway so that the new shortest path passes through a new city.

Log in or sign up to be able to send submissions!