#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
int N,M,s,t,p=0;
int head[10000010],dis[10000010],vis[10000010];
struct edge
{
int to,v,nex;
}e[10000010];
void add(int a,int b,int c)
{
e[++p].v=c;
e[p].to=b;
e[p].nex=head[a];
head[a]=p;
}
struct node
{
int dis,pos;
bool operator < (const node &a) const
{
return dis<a.dis;
}
};
priority_queue <node> q;
void Dij()
{
memset(dis,0x3f,sizeof(dis));
memset(vis,0,sizeof(vis));
dis[s]=0;
q.push((node){0,s});
while(!q.empty())
{
node tmp=q.top();
q.pop();
int x=tmp.pos;
if(vis[x]) continue;
vis[x]=1;
int c=head[x];
while(c)
{
int pd=e[c].to;
if(dis[pd]>max(dis[x],e[c].v))
{
dis[pd]=max(dis[x],e[c].v);
if(!vis[pd]) q.push((node){dis[pd],pd});
}
c=e[c].nex;
}
}
}
int main()
{
scanf("%d %d %d %d",&N,&M,&s,&t);
int u,v,e;
for(int i=1;i<=M;i++)
{
scanf("%d %d %d",&u,&v,&e);
add(u,v,e);
add(v,u,e);
}
Dij();
printf("%d",dis[t]);
return 0;
}