#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, int> pli;
typedef tuple<lli, int, int> tli;
const int maxn = 1e5+10;
const lli inf = 1e18+10;
int N, M, S, T, U, V;
lli dist[maxn];
vector<pii> graph[maxn];
vector<vector<int>> routes[maxn];
void djk1(){
for(int i=1; i<=N; i++) dist[i] = inf;
dist[S] = 0;
priority_queue<tli, vector<tli>, greater<tli>> pq;
pq.push({0, S, 0});
routes[0].push_back({});
while(!pq.empty()){
auto[d, u, p] = pq.top(); pq.pop();
if(dist[u] < d) continue;
for(int i=0; i<(int)routes[p].size(); i++){
routes[u].push_back(routes[p][i]);
routes[u][((int)routes[u].size()-1)].push_back(u);
}
for(auto [v, w] : graph[u]){
if(dist[v] > dist[u]+w){
dist[v] = dist[u]+w;
pq.push({dist[v], v, u});
}
}
}
}
void djk2(){
for(int i=1; i<=N; i++) dist[i] = inf;
dist[U] = 0;
priority_queue<pli, vector<pli>, greater<pli>> pq;
pq.push({0, U});
while(!pq.empty()){
auto[d, u] = pq.top(); pq.pop();
if(dist[u] < d) continue;
for(auto [v, w] : graph[u]){
if(dist[v] > dist[u]+w){
dist[v] = dist[u]+w;
pq.push({dist[v], v});
}
}
}
}
int main() {
cin >> N >> M >> S >> T >> U >> V;
for(int i=0; i<M; i++){
int A, B, C; cin >> A >> B >> C;
graph[A].push_back({B, C});
graph[B].push_back({A, C});
}
djk1();
for(int i=1; i<(int)routes[T][0].size(); i++){
int A = routes[T][0][i], B = routes[T][0][i-1];
graph[A].push_back({B, 0});
graph[B].push_back({A, 0});
}
djk2();
cout << dist[V] << "\n";
}