This page is still under construction.

Parts of this page are still being built. What you see may change.

Two Paths

Time limit1sMemory limit512 MB

Summary
Given a weighted undirected graph, find the shortest walk from node 1 to node n that differs from Alice's chosen shortest path.
Level

Medium7 of 10

Topics
Graph, Shortest path, Dynamic programming, Greedy
Solved
No attempts yet

Problem

You are given an undirected graph with nn nodes (numbered from 11 to nn) and mm edges. Each edge has a length. The graph contains neither multiple edges nor self-loops.

Alice and Bob are playing a game. Each player has to pick a path from 11 to nn (not necessarily a simple path). The paths have to be different.

Alice always moves first, and she is so clever that she took one of the shortest paths from 11 to nn. Now it is Bob's turn. Bob wants to pick the shortest possible path from 11 to nn which is different from Alice's path. Your task is to find the length of such path.

Two paths SS and TT are considered different if and only if they have different number of edges or there is an integer ii such that the ii-th edge of SS differs from the ii-th edge of TT.

Input

The first line of input contains two integers: the number of nodes nn and the number of edges mm (2≤n≤1052 \le n \le 10^5, 1≤m≤1051 \le m \le 10^5). Each of the next mm lines contains three integers aa, bb, and ww which mean that there is an edge between node aa and node bb, and its length is ww (1≤a,b≤n1 \le a, b \le n, 1≤w≤1091 \le w \le 10^9). It is guaranteed that there is at least one path from 11 to nn.

Output

Print a single line with a single integer: the length of a valid shortest path for Bob.

Examples2

  1. Example 1

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

    Input
    2 1
    1 2 1
    
    Expected output
    3