include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 1e4 + 10, M = 2e4 + 10;
int h[N], e[N], ne[N], w[N], idx;
int dis[N];
bool st[N];
int n, m, s, ed;
void insert(int a, int b, int c)
{
e[idx] = b;
w[idx] = c;
ne[idx] = h[a];
h[a] = idx++;
}
void dijkstra()
{
memset(dis, 0x3f, sizeof dis);
dis[s] = 0;
priority_queue<PII, vector<PII>, greater<PII>> heap;
heap.push({ 0,s });
while (heap.size())
{
auto t = heap.top();
heap.pop();
int p = t.second, d = t.first;
if (st[p]) continue;
st[p] = true;
for (int i = h[p]; i != -1; i = ne[i])
{
int j = e[i];
int d1 = w[i];
if (dis[j] > max(d,d1))
{
dis[j] = max(d,d1);
heap.push({ dis[j],j });
}
}
}
cout << dis[ed];
}
int main()
{
cin >> n >> m >> s >> ed;
memset(h, -1, sizeof h);
while (m--)
{
int a, b, c;
cin >> a >> b >> c;
insert(a, b, c);
insert(b, a, c);
}
dijkstra();
return 0;
}