#include<bits/stdc++.h>
using namespace std;
struct node
{
int x,y,v;
}a[100006];
int father[100006];
int flag[100006];
int n,m;
int xx,yy,tmp1,tmp2;
inline int get()
{
int x=0,f=1;
char c;
c=getchar();
if (c==' ') return x*f;
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
return x*f;
}
bool cmp(node a,node b)
{
return a.v>b.v;
}
int find(int x)
{
if (father[x]!=x) father[x]=find(father[x]);
return father[x];
}
void mix(int x,int y)
{
int xx,yy;
xx=find(x);
yy=find(y);
father[yy]=xx;
}
int main()
{
freopen("prison1.in","r",stdin);
freopen("prison1.out","w",stdout);
int i;
n=get();m=get();
for (i=1;i<=n;i++) father[i]=i;
for (i=1;i<=m;i++)
{
a[i].x=get();a[i].y=get();a[i].v=get();
}
sort(a+1,a+m+1,cmp);
for (i=1;i<=m;i++)
{
tmp1=find(a[i].x);
tmp2=find(a[i].y);
if (tmp1==tmp2) {printf("%d",a[i].v);return 0;}
if (flag[a[i].x]==0)
flag[a[i].x]=a[i].y;
if (flag[a[i].y]==0)
flag[a[i].y]=a[i].x;
mix(a[i].x,flag[a[i].y]);
mix(a[i].y,flag[a[i].x]);
}
printf("0");
}