#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; const int INF=1e9+10; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w) {} }; using Graph=vector>; using pli=pair; template bool chmin(T& a,T b){ if(a>b){ a=b; return true; } return false; } int main(){ int n,m; cin>>n>>m; vector S(m),T(m),D(m); rep(i,m){ cin>>S[i]>>T[i]>>D[i]; S[i]--,T[i]--; } map ma; ll ok=0,ng=1e9+7; while(ng-ok>1){ ll mid=(ok+ng)/2; Graph G(n); rep(i,m){ if(D[i] dist(n,INF); int s=0; dist[s]=0; priority_queue,greater> que; que.push({dist[s],s}); while(!que.empty()){ int v=que.top().second; ll d=que.top().first; que.pop(); if(d>dist[v]) continue; for(auto e:G[v]){ if(chmin(dist[e.to],dist[v]+e.w)){ que.push({dist[e.to],e.to}); } } } ma[mid]=dist[n-1]; if(dist[n-1]==INF) ng=mid; else ok=mid; } cout<