Resonant Bridges
An archipelago has platforms connected by resonance bridges. The explorer starts on platform and wants to reach platform .
Each bridge can be crossed in either direction. The -th bridge has crossing time and pitch .
The explorer carries a tuning fork. After she crosses a bridge, the fork keeps the pitch of that bridge. Suppose she is standing on a platform after crossing at least one bridge, the fork currently keeps pitch , and she next wants to cross a bridge with pitch . Before crossing it, she must spend time retuning the fork, and then she spends the bridge's crossing time.
Before the first bridge is crossed, the fork has no pitch, so no retuning time is needed for the first bridge. The explorer may visit the same platform or cross the same bridge multiple times.
Find the minimum possible total time needed to reach platform . If , the explorer is already there and the total time is .
Input
The first line contains two integers and (, ), the number of platforms and bridges.
Output
Print one line containing a single integer: the minimum possible total time to reach platform from platform .
If it is impossible to reach platform , print instead.
Samples
Sample 1
Input
4 4 1 2 5 10 2 4 5 13 1 3 20 100 3 4 1 100
Output
13
One possible trip crosses from platform to platform , then from platform to platform . Its total time is .