#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e4+5,M=1e5+5;
struct node
{
int a,b,c;
bool operator<(const node tt) const
{
if(tt.a==a)
{
return b>tt.b;
}else return a>tt.a;
}
}t[M];
bool cmp(node a,node b)
{
return a.c<b.c;
}
int n,m,l,r,mid;
int fa[N];
int fin(int x)
{
if(fa[x]!=x) fa[x]=fin(fa[x]);
return fa[x];
}
priority_queue<node> Q;
bool check(int x)
{
while(!Q.empty()) Q.pop();
for(int i=1;i<=n;i++) fa[i]=i;
for(int i=n;i>x;i--)
{
Q.push(t[i]);
}
node p=Q.top();
Q.pop();
int f1=p.a,f2=p.b;
while(!Q.empty())
{
node tq=Q.top();
Q.pop();
int tx=fin(tq.a);
int ty=fin(tq.b);
if(tx==ty) return false;
else
{
if(tx==f1)
{
fa[tx]=f2;
if(ty==f1) return false;
else fa[ty]=f1;
}else
{
fa[tx]=f1;
if(ty==f2) return false;
else fa[ty]=f2;
}
}
}
return true;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>t[i].a>>t[i].b>>t[i].c;
if(t[i].a>t[i].b) swap(t[i].a,t[i].b);
Q.push(t[i]);
}
sort(t+1,t+m+1,cmp);
l=1,r=m;
while(l<r)
{
mid=(l+r)/2;
if(check(mid))
{
r=mid;
}else l=mid+1;
}
cout<<t[l].c;
return 0;
}