#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ins insert
#define ff first
#define ss second
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
constexpr int inf = 1e15, mod = 998244353, maxn = 1000005;
int n, m, s, t, u, v;
vector<vector<pair<int,int>>> g;
void solve(){
cin >> n >> m >> s >> t >> u >> v;
g.assign(n+1, vector<pair<int,int>>());
set<tuple<int,int,int>> edg;
for (int i = 0; i < m; i++){
int a, b, w;
cin >> a >> b >> w;
g[a].eb(b, w), g[b].eb(a, w);
edg.ins({a,b,w});
edg.ins({b,a,w});
}
vector<int> dist(n+1, inf), par(n+1, -1);
set<pair<int,int>> q;
q.ins({dist[s]=0,s});
while (!q.empty()){
int a, d;
tie(d, a) = *q.begin();
q.erase(q.begin());
for (auto [b, w]: g[a]){
if (d+w<dist[b]){
par[b]=a;
dist[b]=d+w;
q.ins({dist[b],b});
}
}
}
// cout << dist[t] << '\n';
int x=t;
while (par[x]!=-1){
// (par[x], x)
// cout << "\t**"<< par[x] << ' ' << x << '\n';
auto it = edg.lower_bound({par[x],x,-1});
edg.erase(it);
it = edg.lower_bound({x, par[x], -1});
edg.erase(it);
edg.ins({par[x], x, 0});
edg.ins({x, par[x], 0});
x=par[x];
}
vector<vector<pair<int,int>>> g1(n+1);
for (auto [a, b, w]: edg){
// cout << a << ' ' << b << ' ' << w << '\n';
g1[a].eb(b, w);
g1[b].eb(a, w);
}
dist.assign(n+1, inf);
q.ins({dist[u]=0,u});
while (!q.empty()){
int a, d;
tie(d, a) = *q.begin();
q.erase(q.begin());
for (auto [b, w]: g1[a]){
if (d+w<dist[b]){
dist[b]=d+w;
q.ins({dist[b], b});
}
}
}
cout << dist[v] << '\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
for (int i = 0; i < t; i++) {
solve();
}
return 0;
}