#include<iostream>
using namespace std;
#define Max 1000100
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int p[Max];
struct node{
int x,y,z;
// node (int xx,int yy,int zz):x(xx),y(yy),z(zz){}
friend bool operator<(node n2,node n3){return n2.z>n3.z;}
} n1;
int find(int x){
if(p[x]==x)
return x;
else {
int y=find(p[x]);
p[x]=y;
return y;
}
}
void merge(int x,int y){
p[find(x)]=find(y);
}
int main (){
int n,m,z;
cin>>n>>m;
priority_queue<node>open;
// prority_queue<node>closed;
for(int i=0;i<m;i++)
{ cin>>n1.x>>n1.y>>n1.z;
open.push(n1);
}
for(int i=1;i<=m;i++)
{ p[i]=i;}
for(int i=0;i<m;i++){
node s=open.top();
merge(s.x,s.y);
open.pop();
if(find(1)==find(n)){
z=s.z;
break;
}
}
cout<<z;
return 0;
}
using namespace std;
#define Max 1000100
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int p[Max];
struct node{
int x,y,z;
// node (int xx,int yy,int zz):x(xx),y(yy),z(zz){}
friend bool operator<(node n2,node n3){return n2.z>n3.z;}
} n1;
int find(int x){
if(p[x]==x)
return x;
else {
int y=find(p[x]);
p[x]=y;
return y;
}
}
void merge(int x,int y){
p[find(x)]=find(y);
}
int main (){
int n,m,z;
cin>>n>>m;
priority_queue<node>open;
// prority_queue<node>closed;
for(int i=0;i<m;i++)
{ cin>>n1.x>>n1.y>>n1.z;
open.push(n1);
}
for(int i=1;i<=m;i++)
{ p[i]=i;}
for(int i=0;i<m;i++){
node s=open.top();
merge(s.x,s.y);
open.pop();
if(find(1)==find(n)){
z=s.z;
break;
}
}
cout<<z;
return 0;
}