#include<bits/stdc++.h>
using namespace std;
struct edge{
int l,r,n;
};
edge sb[100000] = {};
int ji[100000] = {};
bool cmp(edge a,edge b)
{
if(a.n>b.n)
{
return 0;
}
return 1;
}
int find(int a)
{
int x = a;
while(ji[x]>=0)
{
x = ji[x];
}
int k = a;
while(ji[k]>=0)
{
ji[k] = x;
k = ji[k];
}
return x;
}
int main()
{
int a,b,c,d,e,n = 0,j = 0;
cin >> a >> b;
for(int i = 0;i<b;i++)
{
cin >> c >> d >> e;
sb[i].l = c-1;
sb[i].r = d-1;
sb[i].n = e;
}
sort(sb,sb+b,cmp);
for(int i = 0;i<a;i++)
{
ji[i] = -1;
}
int res = 0;
while(n!= a-1)
{
if(find(sb[j].l)!= find(sb[j].r)||(find(sb[j].l) == -1||find(sb[j].r) == -1))
{
ji[find(sb[j].l)]+=ji[find(sb[j].r)];
ji[find(sb[j].r)] = find(sb[j].l);
n++;
if(sb[j].n>res)
{
res = sb[j].n;
}
}
j++;
}
cout << res;
return 0;
}