#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define ll long long
#define nl "\n"
#define all(v) v.begin(),v.end()
#define baraa ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
baraa
ll n, m, s, t, x, y;
cin >> n >> m >> s >> t >> x >> y;
vector<array<ll, 3> > edges(2 * m), adj[n + 1];
vector<ll> good(2 * m);
for (ll i = 0, u, v, c; i < 2 * m; i += 2) {
cin >> u >> v >> c;
edges[i] = {u, v, c};
edges[i + 1] = {v, u, c};
adj[u].push_back({v, c, i});
adj[v].push_back({u, c, i + 1});
}
auto dijk = [&](ll st) {
vector<ll> d(n + 1, 1e16);
priority_queue<array<ll, 2>, vector<array<ll, 2> >, greater<> > pq;
pq.push({d[st] = 0, st});
while (pq.size()) {
auto [c, u] = pq.top();
pq.pop();
if (c > d[u])continue;
for (auto [v, w, idx]: adj[u])
if (c + w < d[v])
pq.push({d[v] = c + w, v});
}
return d;
};
auto dS = dijk(s), dT = dijk(t);
for (ll i = 0; i < 2 * m; i++) {
auto [u, v, c] = edges[i];
good[i] = (dS[u] + c + dT[v] == dS[t]);
}
vector d(n + 1, vector<ll>(3, 1e16));
priority_queue<array<ll, 3>, vector<array<ll, 3> >, greater<> > pq;
pq.push({d[x][0] = 0, 0, x});
while (pq.size()) {
auto [cost, state, u] = pq.top();
pq.pop();
if (cost > d[u][state])continue;
for (auto [v, w, idx]: adj[u]) {
if (state != 1 and cost + w < d[v][state])
pq.push({d[v][state] = cost + w, state, v});
else if (state == 1 and cost + w < d[v][2])
pq.push({d[v][2] = cost + w, 2, v});
if (state <= 1 and good[idx] and cost < d[v][1])
pq.push({d[v][1] = cost, 1, v});
}
}
cout << *min_element(all(d[y]));
return 0;
}