Lineville
Lineville is a city in which n houses are arranged in a line. To travel from 1 house to an adjacent house, it takes 1 minute. Fortunately, there are m transport services which take you from one house to another, taking a particular amount of time. These services exist in one direction, but not necessarily the other. What is the shortest time it takes to travel from house 1 to house n?
Input
The first line contains the integer n and m.
The following m lines contains 3 integers: a,b,c. There exists a transport service from house a to b which takes c minutes.
Output
Output the time in minutes to travel from house 1 to house n.
Constraints
- 1≤a,b≤n≤10000
- 1≤m≤1000
- 1≤c≤109
Example 1
5 5
4 4 1
3 2 2
5 4 2
1 4 1
3 2 2
2
Example 2
10 10
9 8 2
5 6 5
8 10 4
9 1 4
4 10 1
8 5 2
6 4 5
3 3 2
6 10 5
6 1 5
4
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.