#include <bits/stdc++.h>
#define N 100005
#define int long long
using namespace std;

typedef pair<int,int> P;

int n, m, s, t;
vector<P> G[N];

void add_edge(int A, int B, int C){
  G[A].push_back(P(B, C));
  G[B].push_back(P(A, C));
}

int d[N];
const int INF = 1e18;

int dijkstra(){

  for(int i=0;i<n;i++) d[i] = INF;
  
  priority_queue<P,vector<P>,greater<P> > q;

  q.push(P( 0, s ));
  d[s] = 0;

  while(!q.empty()){
    
    P tmp = q.top(); q.pop();

    int node = tmp.second;
    int cost = tmp.first;

    if( node == t ) return cost;
    if( d[node] < cost ) continue;
    
    for(auto p : G[node] ){
      
      int nnode = p.first;
      int ncost = cost + p.second;

      if( d[nnode] > ncost ){
	d[nnode] = ncost;
	q.push(P( ncost, nnode ));
      }
    }
    
  }
  
}

signed main(){
  
  cin>>n>>m>>s>>t;
  
  s--, t--;
  
  for(int i=0;i<m;i++){
    
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    
    a--, b--, c--;
    
    add_edge( a, b, d );
    add_edge( a, c, d );
    add_edge( b, c, d );
  }
  
  cout<<dijkstra()<<endl;
  
  return 0;
}

