#include #define int long long using namespace std; int inf=1e18; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,m;cin>>n>>m; vector>>g(n); for(int i=0;i>u>>v>>h; u--;v--; g[u].push_back({v,h}); g[v].push_back({u,h}); } int ng=1e10,ok=0; while(ng-ok>1){ int c=(ok+ng)/2; vectorvis(n); vis[0]=true; dequeque; que.push_back(0); while(!que.empty()){ int now=que.front(); que.pop_front(); for(auto to:g[now]){ if(c<=to.second&&!vis[to.first]){ vis[to.first]=true; que.push_back(to.first); } } } if(vis[n-1])ok=c; else ng=c; } if(ok==0){ cout<<"NaN"<