#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define HUGE_NUM 99999999999999999
#define NUM 100001

enum Type{
	from_S,
	from_T,
	from_U,
	from_V,
};

struct Edge{
	Edge(int arg_to,ll arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to;
	ll cost;
};

struct Info{
	Info(int arg_node_id,ll arg_sum_cost){
		node_id = arg_node_id;
		sum_cost = arg_sum_cost;
	}
	bool operator<(const struct Info & arg) const{
		return sum_cost > arg.sum_cost;
	}

	int node_id;
	ll sum_cost;
};

struct Data{
	Data(int arg_node_id,ll arg_dist){
		node_id = arg_node_id;
		dist = arg_dist;
	}
	bool operator<(const struct Data &arg) const{
		return dist < arg.dist;
	}

	int node_id;
	ll dist;
};

int N,M,S,T,U,V;
int start[4];
vector<Edge> G[NUM];
ll min_dist[NUM][4],min_dist_from_U[NUM];

void calc(Type type){

	for(int i = 1; i <= N; i++){
		min_dist[i][type] = HUGE_NUM;
	}

	min_dist[start[type]][type] = 0;

	priority_queue<Info> Q;
	Q.push(Info(start[type],0));

	int next_node;
	ll next_cost;

	while(!Q.empty()){
		if(Q.top().sum_cost > min_dist[Q.top().node_id][type]){
			Q.pop();
		}else{

			for(int i = 0; i < G[Q.top().node_id].size(); i++){
				next_node = G[Q.top().node_id][i].to;
				next_cost = Q.top().sum_cost+G[Q.top().node_id][i].cost;

				if(min_dist[next_node][type] > next_cost){
					min_dist[next_node][type] = next_cost;
					Q.push(Info(next_node,next_cost));
				}
			}
			Q.pop();
		}
	}
}

int main(){

	scanf("%d %d",&N,&M);
	scanf("%d %d",&S,&T);
	scanf("%d %d",&U,&V);

	start[from_S] = S;
	start[from_T] = T;
	start[from_U] = U;
	start[from_V] = V;

	int from,to;
	ll cost;

	for(int loop = 0; loop < M; loop++){
		scanf("%d %d %lld",&from,&to,&cost);
		G[from].push_back(Edge(to,cost));
		G[to].push_back(Edge(from,cost));
	}

	calc(from_S);
	calc(from_T);
	calc(from_U);
	calc(from_V);

	vector<Data> DATA;

	for(int i = 1; i <= N; i++){
		DATA.push_back(Data(i,min_dist[i][from_S]));
	}
	sort(DATA.begin(),DATA.end());

	ll ans = min_dist[V][from_U];
	int node_id,adj_node;

	for(int i = 1; i <= N; i++)min_dist_from_U[i] = min_dist[i][from_U];

	for(int i = 0; i < DATA.size(); i++){
		node_id = DATA[i].node_id;
		ans = min(ans,min_dist[node_id][from_U]+min_dist[node_id][from_V]);
		for(int k = 0; k < G[node_id].size(); k++){
			adj_node = G[node_id][k].to;
			if(min_dist[node_id][from_S]+G[node_id][k].cost+min_dist[adj_node][from_T] != min_dist[T][from_S])continue;
			min_dist[adj_node][from_U] = min(min_dist[adj_node][from_U],min_dist[node_id][from_U]);
		}
	}

	for(int i = 0; i < DATA.size(); i++){
		node_id = DATA[i].node_id;
		ans = min(ans,min_dist[node_id][from_V]+min_dist_from_U[node_id]);
		for(int k = 0; k < G[node_id].size(); k++){
			adj_node = G[node_id][k].to;
			if(min_dist[node_id][from_S]+G[node_id][k].cost+min_dist[adj_node][from_T] != min_dist[T][from_S])continue;
			min_dist[adj_node][from_V] = min(min_dist[adj_node][from_V],min_dist[node_id][from_V]);
		}
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 23088