#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

const LL inf = 11234567890123456;
LL N, M, s, t;
std::vector<LL>a, b, c, d, dist;
std::vector<std::vector<edge>>G;

void dijkstra(int s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	std::fill(dist.begin(), dist.end(), inf);
	dist[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (dist[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (dist[e.to] > dist[v] + e.cost)
			{
				dist[e.to] = dist[v] + e.cost;
				que.push(P(dist[e.to], e.to));
			}
		}
	}
}

int main()
{
	in >> N >> M >> s >> t;
	a.resize(M), b.resize(M), c.resize(M), d.resize(M);
	G.resize(N + 1), dist.resize(N + 1);
	rep(i, M) in >> a[i] >> b[i] >> c[i] >> d[i];
	rep(i, M)
	{
		G[a[i]].push_back({ b[i],d[i] });
		G[b[i]].push_back({ a[i],d[i] });
		G[a[i]].push_back({ c[i],d[i] });
		G[c[i]].push_back({ a[i],d[i] });
		G[b[i]].push_back({ c[i],d[i] });
		G[c[i]].push_back({ b[i],d[i] });
	}
	dijkstra(s);
	out << dist[t] << std::endl;
	return 0;
}
