Lineville is a city inwhich houses are arranged in a line. To travel from 1 house to an adjacent house, it takes 1 minute. Fortunately, there are
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
.
Input
The first line contains the integer and
.
The following
lines contains 3 integers:
. There exists a transport service from house
to
which takes
minutes.
Output
Output the time in minutes to travel from house to house
.
Constraints
Case 1
Input
5 5
4 4 1
3 2 2
5 4 2
1 4 1
3 2 2
Output
2
Case 2
Input
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
Output
4
Comments