int fa[maxn], e[maxn]; voidinit_fa(){ for (int i = 1; i <= n; ++i) fa[i] = i; }
intfind(int x){ return x == fa[x] ? x : fa[x] = find(fa[x]); }
inlinevoidmerge(int x, int y){ int fx = find(x), fy = find(y); if (fx == fy) return ; fa[fx] = fy; }
int ans; intmain(){ cin >> n >> m; for (int i = 1; i <= m; ++i) scanf("%d%d%d", &a[i].u, &a[i].v, &a[i].w); sort(a + 1, a + m + 1); init_fa(); for (int i = 1; i <= m; ++i) { int u = a[i].u, v = a[i].v, w = a[i].w, fu = find(u), fv = find(v); if (fu == fv) { ans = w; break; } if (!e[u]) e[u] = v; else merge(e[u], v); if (!e[v]) e[v] = u; else merge(e[v], u); } cout << ans << endl; return0; }