#include <cstdio> #include <iostream> #include <algorithm> using namespace std; int n,m,p[1010],t,cnt,ans,sum; struct edge{int u,v,w;}e[100010]; bool cmp(edge x,edge y){return x.w<y.w;} int find(int x){return x==p[x]?x:p[x]=find(p[x]);} int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)p[i]=i; while(m--){ int u,v,w; scanf("%d%d%d",&u,&v,&w); e[++cnt].u=u; e[cnt].v=v; e[cnt].w=w; } sort(e+1,e+cnt+1,cmp); for(register int i=1;i<=cnt;i++){ int x=find(e[i].u),y=find(e[i].v); if(x!=y){ p[x]=y; sum++; ans=e[i].w; } } if(sum==n-1)printf("%d ",ans); else puts("-1"); return 0; }