The subway system in Barareh consists of stations and subway lines. The stations are numbered from to . Each line is managed by a company and each company has a unique identifier. The subway line is managed by company and connects only two stations, and , in both directions. When arriving at a station, if more than one subway line is connected to that station, passengers can easily switch between lines. The cost of using the subway in Barareh is a bit different.
When a passenger uses only subway lines operated by a single company, he only need to pay Bararehian dollar. However, if a passenger changes their subway line at a station, and these two lines are managed by different companies, he have to pay an additional Bararehian dollar. In other words, the passenger pays Bararehian dollar at the first station, and then at each intermediate station, they only need to pay an additional Bararehian dollar if the two lines used for arriving and departing the station belong to different companies.
Calculate the minimum cost required to travel from station to station .
The first line of the input consists of two integers and separated by a space, which is the number of stations and the number of subway lines, respectively. Then, for each , the line of input contains three integers , , and , separated by a space .
In the only line of output, if it is impossible to travel from station to station using the subway lines, print . Otherwise, print the minimum cost required to travel from station to station .
In the example above, initially, one can traverse the following path by paying Bararehian dollar: Then, with another Bararehian dollar payment, continue the path as follows: .