#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<60)

//verified AOJ GRL_1
#define MAX_V 100000
template <typename T>
struct edge{int to;T cost;};

template <typename T>
void dijkstra(int s, vector<T> &d, vector<edge<T>> G[MAX_V]){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep( i,d.size() )d[i]=INF;
    d[s] = 0;
    que.push( pii(0,s) );
    
    while( que.size() ){
        pii p=que.top();
        que.pop();
        
        int v=p.second;
        if(d[v]<p.first)continue;
        
        rep(i,G[v].size()){
            edge<T> e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}


signed main(){
    vector<edge<int>> G[MAX_V];
    int v,e,s,t;
    cin>>v>>e>>s>>t;
    s--,t--;
    
    rep(i,e){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        a--,b--,c--;
        G[a].pb(edge<int>{b,d});
        G[a].pb(edge<int>{c,d});
        G[b].pb(edge<int>{a,d});
        G[b].pb(edge<int>{c,d});
        G[c].pb(edge<int>{a,d});
        G[c].pb(edge<int>{b,d});
    }
    
    vector<int> d(MAX_V);
    dijkstra(s,d,G);
    
    cout<<d[t]<<endl;
}

