#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const long long int INF = 1e15;
vector<long long int> dijkstra(int s, int v, vector< vector< pair<int,int> > > G){
  //s: 始点, v: 頂点数, G: 隣接リスト
  priority_queue< pair<long long int, int> > wait;
  vector<long long int> result(v, INF);
  result[s] = 0;
  wait.push(make_pair(0, s));
  while(!wait.empty()){
    long long int nowpoint = wait.top().second;
    long long int nowcost = wait.top().first;
    wait.pop();
    if(nowcost <= result[nowpoint]){
      for(int i = 0; i < G[nowpoint].size(); ++i){
        long long int nextpoint = G[nowpoint][i].second;
        long long int nextcost = -nowcost + G[nowpoint][i].first;
        if(nextcost < result[nextpoint]){
          wait.push(make_pair(-nextcost, nextpoint));
          result[nextpoint] = nextcost;
        }
      }
    }
  }
  return result;
}

int main(){
  int N, M, s, t;
  cin >> N >> M >> s >> t;
  --s;--t;
  vector< vector< pair<int, int> > > G(N);
  int a, b, c, d;
  for(int i = 0; i < M; ++i){
    cin >> a >> b >> c >> d;
    --a;--b;--c;
    G[a].emplace_back(d,b);
    G[a].emplace_back(d,c);
    G[b].emplace_back(d,a);
    G[b].emplace_back(d,c);
    G[c].emplace_back(d,a);
    G[c].emplace_back(d,b);
  }
  cout << dijkstra(s,N,G)[t] << endl;
  return 0;
}

