#include using namespace std; typedef long long ll; struct edge{ ll p;//点 ll w;//辺の重み*-1 }; vector > graph(100000); vector dis(100000); ll v,e,r;//vは頂点,eは辺,rは始点 void dijkstra(){ for(int i = 0;i < v;i++)dis[i] = pow(10,18); dis[r] = 0; priority_queue > que;//重み、頂点 que.push(make_pair(0,r)); while(!que.empty()){ edge now; now.p = que.top().second; now.w = que.top().first * -1; que.pop(); if(dis[now.p] < now.w)continue; for(int i = 0;i < (int)graph[now.p].size();i++){ if(dis[graph[now.p][i].p] > now.w + graph[now.p][i].w){ dis[graph[now.p][i].p] = now.w + graph[now.p][i].w; que.push(make_pair(dis[graph[now.p][i].p] * -1,graph[now.p][i].p)); } } } } int main(){ cin >> v >> e; for(int i = 0;i < e;i++){ ll a,b,c; cin >> a >> b >> c; a--,b--; edge ma = {b,c}; edge mb = {a,c}; graph[a].push_back(ma); graph[b].push_back(mb); } r = 0; dijkstra(); cout << dis[v - 1] * 2 << endl; }