#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using P = pair<int, int>;
#define all(x) x.begin(), x.end()
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e)?x++:x--))
#define sz(x) (int)x.size()
const char nl = '\n';
const int inf = 1e5*1e9;
const int NMAX = 1e5+10;
vector<P> g[NMAX];
int in[NMAX];
void djk(int src, vector<int> &d) {
for (auto &i: d)i = inf; d[src] = 0;
priority_queue<P, vector<P>, greater<P>> pq;
pq.push(P(0, src));
while (!pq.empty()) {
auto [dist, nd] = pq.top(); pq.pop();
if (d[nd] != dist)continue;
for (auto [ch, w]: g[nd])
if (dist+w < d[ch])
d[ch] = dist+w,
pq.push({d[ch], ch});
}
}
void solve() {
int n, m; cin >> n >> m;
int s, t; cin >> s >> t;
int u, v; cin >> u >> v;
while (m--) {
int x, y, z; cin >> x >> y >> z;
g[x].push_back(P(y, z));
g[y].push_back(P(x, z));
}
vector<int> ds(n+1), dt(n+1), du(n+1), dv(n+1);
djk(s, ds), djk(t, dt);
djk(u, du), djk(v, dv);
vector<int> g2[n+1];
rep(i, 1, n+1) {
for (auto [j, w]: g[i])
if (ds[i]+dt[j]+w == ds[t])
g2[i].push_back(j),
in[j] += 1;
}
vector<int> dp1(n+1, inf), dp2(n+1, inf);
int res = du[v];
queue<int> q; q.push(s);
while (!q.empty()) {
int nd = q.front(); q.pop();
dp1[nd] = min(dp1[nd], du[nd]);
dp2[nd] = min(dp2[nd], dv[nd]);
for (auto i: g2[nd]) {
dp1[i] = min(dp1[i], dp1[nd]);
dp2[i] = min(dp2[i], dp2[nd]);
in[i] -= 1;
if (in[i] == 0)q.push(i);
}
res = min(res, min(dp1[nd]+dv[nd], dp2[nd]+du[nd]));
}
cout << res << nl;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}