#include<bits/stdc++.h>
using namespace std;
int n,m;
int fa[100005];
struct xx{
int x,y,t;
}f[100005];
void makeSet(int n)
{
for(int i=1;i<=n;i++)
{
fa[i]=i;
}
}
bool cmp(xx x,xx y)
{
return x.t<y.t;
}
int find(int x) {
if (x != fa[x]) fa[x] = find(fa[x]);
return fa[x];
}
void unionSet(int x, int y) {
x = find(x);
y = find(y);
fa[x] = y;
return;
}
bool check(int x)
{
int s=find(x);
for(int i=1;i<=n;i++)
{
if(s!=find(fa[i]))
{
return false;
}
}
return true;
}
int main()
{
int n,m;
cin>>n>>m;
makeSet(n);
for(int i=1;i<=m;i++)
{
cin>>f[i].x>>f[i].y>>f[i].t;
// if(f[i].x<f[i].y)
// swap(f[i].x,f[i].y);
}
sort(f+1,f+1+n,cmp);
for(int i=1;i<=m;i++)
{
unionSet(f[i].x,f[i].y);
if(check(f[i].x))
{
cout<<f[i].t;
return 0;
}
}
cout<<"-1";
return 0;
}
P1111 求助 为什么 跑if(check()) 第一层就出来