#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<<]; inline int read()
{
int s=,m=;char ch=getchar();
while(ch!='-'&&(ch<''||ch>''))ch=getchar();
if(ch=='-')m=-,ch=getchar();
while(ch>=''&&ch<='')s=(s<<)+(s<<)+ch-'',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=;i<=m;++i)
{
ljl[i].l=read();ljl[i].r=read();ljl[i].v=read();
}
sort(ljl+,ljl+m+,cmp);
for(int i=;i<=n<<;++i)
{
fa[i]=i;
}
for(int i=;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();
}
else
{
add(ljl[i].l,ljl[i].r+n);
add(ljl[i].r,ljl[i].l+n);
}
}
puts("");
return ;
}