/*
auther: FPythonX
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
// #pragma GCC optimize("Ofast,O3,unroll-loops")
// #pragma GCC target("avx,avx2")
using namespace std;
using namespace chrono;
// using namespace __gnu_pbds;
#define int long long
#define vi vector<int>
#define vch vector<char>
#define vs vector<string>
#define vvi vector<vector<int>>
#define vvh vector<vector<char>>
#define vvs vector<vector<string>>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define endl '\n'
#define vpii vector<pair<int,int>>
#define vvpii vector<vector<pair<int, int>>>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (int)((a * b) / __gcd(a, b))
#define ff first
#define sd second
#define pb push_back
#define sz(x) (int)x.size()
const int inf = 1e18;
void fre_open(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef FPythonX
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
void FPythonX(){
int n, m; cin >> n >> m;
int s, t, uu, vv; cin >> s >> t >> uu >> vv;
vvpii g(n + 1);
for(int i = 0; i < m; i++){
int u, v, w; cin >> u >> v >> w;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vi dist1(n + 1, inf);
vi p(n + 1, -1);
priority_queue<pii> q;
q.push({0, s});
dist1[s] = 0;
while(!q.empty()){
auto [w, u] = q.top(); q.pop();
w = -w;
if(dist1[u] < w) continue;
for(auto &[v, x] : g[u]){
if(dist1[v] > dist1[u] + x){
dist1[v] = dist1[u] + x;
p[v] = u;
q.push({-dist1[v], v});
}
}
}
vi path;
int cr = t;
while(cr != s){
path.push_back(cr);
cr = p[cr];
}
path.push_back(cr);
reverse(all(path));
for(int i = 1; i < sz(path); i++){
int u = path[i - 1];
int v = path[i];
g[u].push_back({v, 0});
g[v].push_back({u, 0});
}
vi dist2(n + 1, inf);
priority_queue<pii> qq;
qq.push({0, uu});
dist2[uu] = 0;
while(!qq.empty()){
auto [w, u] = qq.top(); qq.pop();
w = -w;
if(dist2[u] < w) continue;
for(auto &[v, x] : g[u]){
if(dist2[v] > dist2[u] + x){
dist2[v] = dist2[u] + x;
qq.push({-dist2[v], v});
}
}
}
cout << dist2[vv] << endl;
}
signed main(){
auto start = high_resolution_clock::now();
fre_open();
int t = 1;
// cin >> t;
while(t--) FPythonX();
auto end = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(end - start);
cerr << "Kod " << duration.count() << " ms da ishladi." << endl;
return 0;
}