#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = INT_MAX;
const int N = 1e5 + 1;
vector<pair<int,ll>>graph[N];
int n,m,s,t,u,v;
bool vis[N];
ll store[N] = {MAX};
map<pair<int, int>, bool> mp;
void dijkstra(int source){
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
pq.push({0,source});
for(int i=0; i<N; i++){
store[i] = MAX;
}
store[source] = 0;
vector<int>path(n+1);
while(!pq.empty()){
auto top = pq.top();
pq.pop();
vis[top.second] = true;
for(auto i: graph[top.second]){
if(!vis[i.first]){
if(store[i.first] == MAX){
pq.push({top.first + i.second, i.first});
path[i.first] = top.second;
}
if(store[i.first] > top.first + i.second){
store[i.first] = top.first + i.second;
path[i.first] = top.second;
}
}
}
}
path[source] = -1;
int i = t;
while(path[i] != -1){
mp[{i, path[i]}] = 1;
mp[{path[i], i}] = 1;
i = path[i];
}
}
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});
}
dijkstra(s);
for(int i=1; i <= n; i++){
store[i]=0;
vis[i]= 0;
}
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
pq.push({0,u});
for(int i=0; i<N; i++){
store[i] = MAX;
}
store[u] = 0;
while(!pq.empty()){
auto top = pq.top();
pq.pop();
for(auto i: graph[top.second]){
if(store[i.first] == MAX){
pq.push({(mp[{top.second, i.first}] ? 0 : top.first + i.second), i.first});
}
if(store[i.first] > top.first + i.second){
store[i.first] = top.first + i.second;
}
}
}
cout<<store[v]<<endl;
}