#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin>>n>>m;
int s, t;
cin>>s>>t;
int u, v;
cin>>u>>v;
vector<pair<int, ll>> adj[n + 1];
for(int i=0;i<m;++i) {
int u, v;
ll w;
cin>>u>>v>>w;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
vector<ll> dist(n + 1, LLONG_MAX);
pq.push({0, u});
dist[u] = 0;
while(!pq.empty()) {
auto p = pq.top();
pq.pop();
if(p.F > dist[p.S]) {
continue;
}
for(auto &q : adj[p.S]) {
if(dist[p.S] + q.S < dist[q.F]) {
dist[q.F] = dist[p.S] + q.S;
pq.push({dist[q.F], q.F});
}
}
}
cout<<dist[v]<<'\n';
return 0;
}