#include<iostream> #include<cstdlib> #include<cstdio> #include<cmath> #include<cstring> #include<iomanip> #include<algorithm> #include<queue> #include<ctime> #define ll long long #define rg register #define M 100050 #define N 20050 using namespace std; int n,m; struct war{ int l,r,v; }ljl[M]; int fa[N<<1]; inline int read() { int s=0,m=1;char ch=getchar(); while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar(); if(ch=='-')m=-1,ch=getchar(); while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+ch-'0',ch=getchar(); return s*m; } inline bool cmp(const war &a,const war &b) { return a.v>b.v; } int find_fa(int kk) { if(fa[kk]==kk)return kk; else { fa[kk]=find_fa(fa[kk]); return fa[kk]; } } void add(int k1,int k2) { int fa1=find_fa(k1); int fa2=find_fa(k2); fa[fa1]=fa2; } int main() { n=read();m=read(); for(int i=1;i<=m;++i) { ljl[i].l=read();ljl[i].r=read();ljl[i].v=read(); } sort(ljl+1,ljl+m+1,cmp); for(int i=1;i<=n<<1;++i) { fa[i]=i; } for(int i=1;i<=m;++i) { int f1=find_fa(ljl[i].l); int f2=find_fa(ljl[i].r); if(f1==f2) { printf("%d\n",ljl[i].v); exit(0); } else { add(ljl[i].l,ljl[i].r+n); add(ljl[i].r,ljl[i].l+n); } } puts("0"); return 0; }