var a,b,c:array[0..100009] of longint;f:array[0..40009] of longint;
x,y,ans,i,n,m:longint;
procedure qsort(l,r:longint);
var i,j,bi,ti:longint;
begin
i:=l;
j:=r;
bi:=c[(l+r) div 2];
repeat
while c[i]>bi do inc(i);
while c[j]<bi do dec(j);
if i<=j then
begin
ti:=a[i];a[i]:=a[j];a[j]:=ti;
ti:=b[i];b[i]:=b[j];b[j]:=ti;
ti:=c[i];c[i]:=c[j];c[j]:=ti;
inc(i); dec(j);
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
function find(x:longint):longint;
begin
if f[x]=x then exit(x);
f[x]:=find(f[x]);
exit(f[x]);
end;
begin
assign(input,'prison1.in');reset(input);
assign(output,'prison1.out');rewrite(output);
read(n,m);
for i:=1 to m do read(a[i],b[i],c[i]);
qsort(1,m);
for i:=1 to 2*n do f[i]:=i;
for i:=1 to m do
begin
if find(a[i])=find(b[i]) then
begin
ans:=c[i];
break;
end else
begin
f[find(a[i])]:=find(b[i]+n);
f[find(b[i])]:=find(a[i]+n);
end;
end;
write(ans);
close(input);close(output);
end.