#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m,s,t;
	cin>>n>>m>>s>>t;
	s--;
	t--;
	vector<vector<P>> adj(n);
	REP(i,m) {
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		a--;
		b--;
		c--;
		adj[a].pb(P(c,d));
		adj[b].pb(P(c,d));
		adj[b].pb(P(a,d));
		adj[c].pb(P(a,d));
		adj[c].pb(P(b,d));
		adj[a].pb(P(b,d));
	}
	vector<ll> d(n,INF*INF);
	d[s]=0;
	priority_queue<P,vector<P>,greater<P>> q;
	q.push(P(0,s));
	while(!q.empty()) {
		ll p=q.top().second;
		ll c=q.top().first;
		q.pop();
		if(d[p]!=c) continue;
		REP(i,adj[p].size()) {
			ll next=adj[p][i].first;
			ll cost=adj[p][i].second;
			if(d[next]>d[p]+cost) {
				d[next]=d[p]+cost;
				q.push(P(d[next],next));
			}
		}
	}
	cout<<d[t]<<endl;
}

