#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, m, s, t, tot;
int d[maxn], st[maxn];
bool vis[maxn];
queue<int> q;
struct node{
int v, w, nxt;
} edge[2*maxn];
inline void in(int x, int y, int z){
edge[++tot].v = y;
edge[tot].w = z;
edge[tot].nxt = st[x];
st[x] = tot;
}
inline void spfa(){
memset(d, 0x3f3f3f3f, sizeof(d));
q.push(s);
vis[s] = 1;
d[s] = 0;
while(!q.empty()){
int now = q.front(); q.pop();
vis[now] = 0;
for(int i = st[now]; i; i = edge[i].nxt){
int to = edge[i].v;
if(max(d[now], edge[i].w) < d[to]){
d[to] = max(d[now], edge[i].w);
vis[to] = 1;
q.push(to);
}
}
}
}
int main(){
scanf("%d%d%d%d", &n, &m, &s, &t);
for(int i = 1, x, y, z; i <= m; i++){
scanf("%d%d%d", &x, &y, &z);
in(x, y, z);
in(y, x, z);
}
spfa();
printf("%d\n", d[t]);
return 0;
}