#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int n, m, S, T, U, V;
int a[SIZE], b[SIZE], c[SIZE];

vector<pair<int, int> > G[SIZE];
vector<pair<int, int> > G2[SIZE];
vector<pair<int, int> > G2r[SIZE];

void dijkstra(vector<pair<int,int> > *G, int q, int *start, ll *res){
  priority_queue<pair<pair<ll,int>,int> > pq;
  bool visited[3][SIZE] = {};
  
  for(int i=0;i<q;i++){
    pq.push({{0, start[i]},0});
  }

  while(pq.size()){
    auto p = pq.top();
    pq.pop();

    int now = p.first.second;
    ll cost = p.first.first;
    int f = p.second;
    
    if(visited[f][now]) continue;
    if(!visited[0][now] && !visited[1][now] && !visited[2][now])
      res[now] = -cost;

    visited[f][now] = true;

    for(int i=0;i<G[now].size();i++){
      if(G[now][i].first == -1){
        if(f == 0 || f == 1)
          pq.push({{cost, G[now][i].second},1});
      }else{
        if(f == 0)
          pq.push({{cost - c[G[now][i].first], G[now][i].second},0});
        else
          pq.push({{cost - c[G[now][i].first], G[now][i].second},2});
      }
    }
  }
  
}

int main(){
  ll res1[SIZE], res2[SIZE];
  int start[SIZE];
  scanf("%d%d%d%d%d%d",&n,&m,&S,&T,&U,&V);
  S--; T--; U--; V--;

  for(int i=0;i<m;i++){
    scanf("%d%d%d",a+i, b+i, c+i);
    a[i]--; b[i]--;

    G[a[i]].push_back({i, b[i]});
    G[b[i]].push_back({i, a[i]});
  }

  start[0] = S;
  for(int i=0;i<n;i++) res1[i] = -1;
  dijkstra(G, 1, start, res1);
  
  queue<int> que;
  bool visited[SIZE] = {};
  que.push(T);

  for(int i=0;i<n;i++) G2r[i] = G[i];
  for(int i=0;i<n;i++) G2[i] = G[i];
  
  while(que.size()){
    int p = que.front();
    que.pop();

    if(visited[p]) continue;
    visited[p] = true;
    
    for(int i=0;i<G[p].size();i++){
      if(res1[p] - c[G[p][i].first] == res1[G[p][i].second]){
        que.push(G[p][i].second);
        G2r[p].push_back({-1, G[p][i].second});
        G2[G[p][i].second].push_back({-1, p});
      }
    }
  }

  start[0] = V;
  for(int i=0;i<n;i++) res1[i] = -1;
  for(int i=0;i<n;i++) res2[i] = -1;
  dijkstra(G2, 1, start, res1);
  dijkstra(G2r, 1, start, res2);

  cout << min(res1[U], res2[U]) << endl;
  
  return 0;
}

