#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   int n, m, fa[N], f[N], d[N], head[N], xx, yy, ww, fr[N];   int ans;   bool in[N], c[N];   struct nd {     int x, y, w, id;   } a[N];   bool operator<(nd a, nd b) { return a.w < b.w || (a.w == b.w && a.id < b.id); }   struct ndd {     int ne, to, w;   } e[N];   void ins(int x, int y, int w) {     static int cnt;     e[++cnt].to = y;     e[cnt].ne = head[x];     head[x] = cnt;     e[cnt].w = w;   }   int gf(int x) { return fa[x] == x ? x : fa[x] = gf(fa[x]); }   void dfs(int x) {     for (int i = head[x]; i; i = e[i].ne)       if (e[i].to != f[x]) {         int y = e[i].to;         f[y] = x;         d[y] = d[x] + 1;         fr[y] = e[i].w;         dfs(y);       }   }   void col(int x, int b) {     c[x] = 1;     for (int i = head[x]; i; i = e[i].ne)       if (e[i].to != b) {         int y = e[i].to;         col(y, x);       }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &a[i].x, &a[i].y, &a[i].w);       a[i].id = i;     }     xx = a[1].x, yy = a[1].y, ww = a[1].w;     sort(a + 1, a + m + 1);     for (int i = 1; i <= n; ++i) fa[i] = i;     for (int i = 1; i <= m; ++i) {       int fx = gf(a[i].x), fy = gf(a[i].y);       if (fx != fy) {         fa[fx] = fy;         in[a[i].id] = 1;         ins(a[i].x, a[i].y, a[i].w);         ins(a[i].y, a[i].x, a[i].w);       }     }     d[1] = 1;     dfs(1);     if (!in[1]) {       while (xx != yy) {         if (d[xx] < d[yy]) swap(xx, yy);         ans = max(ans, fr[xx]);         xx = f[xx];       }     } else {       ans = 1e9;       col(yy, xx);       for (int i = 1; i <= m; ++i)         if (!in[a[i].id]) {           if (c[a[i].x] ^ c[a[i].y]) ans = min(ans, a[i].w);         }     }     printf( %d n , ans);   }   