Under construction

Still being built. Things may change

Aesthetic

Time limit2sMemory limit1024 MB

Summary
Given a connected weighted graph whose roads are ordered by aesthetics, pick one pair i<j that adds W_j to W_i, maximizing the shortest 1-to-N distance afterward.
Level

Hard8 of 10

Topics
Graph, Shortest path
Solved
No attempts yet

Problem

Syrup the Turtle lives in a town with a layout of NN locations connected by MM roads. Locations are numbered 1,2,…,N1, 2, \ldots, N and roads are numbered 1,2,…,M1, 2, \ldots, M. Road ii directly connects locations AiA_i and BiB_i, has length WiW_i, and can be traveled in either direction. Any two locations can reach each other directly or indirectly, and no two roads share the same pair of endpoints.

Each road has its own scenery. The residents agree on how aesthetically pleasing each road is, and the roads become more aesthetic as the index grows, from road 1 to road MM.

The residents want to refine the town further. An identical copy of a more aesthetic road is built on top of a strictly less aesthetic road. Road jj can be copied onto road ii if and only if i<ji < j, and this changes the length of road ii to Wi+WjW_i + W_j. The residents vote for exactly one pair of roads to carry out this project.

Syrup makes frequent trips between his house at location NN and the main square at location 11. Find the maximum possible length of the shortest path between locations 11 and NN after the project is done.

Input

The first line contains NN and MM. Each of the next MM lines contains AiA_i, BiB_i, and WiW_i, describing road ii.

Output

Print a single integer on one line: the maximum possible length of the shortest path between locations 11 and NN after the project.

Constraints

3≤N≤3000003 \le N \le 300000

2≤M≤3000002 \le M \le 300000

1≤Ai≠Bi≤N1 \le A_i \ne B_i \le N

0≤Wi≤1090 \le W_i \le 10^9

Examples4

  1. Example 1

    Input
    6 8
    5 6 2
    3 1 4
    1 2 2
    6 2 3
    5 3 3
    3 2 1
    4 6 3
    2 4 2
    
    Expected output
    8
    
  2. Example 2

    Input
    5 6
    1 2 1
    4 3 1
    2 4 1
    3 2 1
    1 3 1
    4 5 1
    
    Expected output
    3
    
  3. Example 3

    Input
    7 6
    2 1 4
    1 3 3
    4 5 4
    5 7 3
    4 6 2
    1 4 0
    
    Expected output
    10
    
  4. Example 4

    Input
    5 5
    4 3 3
    1 4 4
    3 1 3
    4 5 2
    2 3 1
    
    Expected output
    8