#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
typedef pair<int,int> PII;
const int N=5e5+10;
vector<PII> g[N];
int n,m,s,t;
int dist[N];
bool vis[N];
void init()
{
for(int i=0;i<=n;i++)
{
dist[i]=INF;
g[i].clear();
vis[i]=false;
}
}
void dijkstra()
{
dist[s]=0;
priority_queue<PII,vector<PII>,greater<PII>> q;
q.push({dist[s],s});
while(q.size())
{
int u=q.top().second;
q.pop();
if(vis[u])continue;
vis[u]=true;
for(auto [v,w]:g[u])
{
if(dist[v]>dist[u]+w)
{
dist[v]=dist[u]+w;
q.push({dist[v],v});
}
}
}
}
void solve()
{
init();
for(int i=0;i<m;i++)
{
int u,v,w;
cin>>u>>v>>w;
g[u].push_back({v,w});
g[v].push_back({u,w});
}
cin>>s>>t;
dijkstra();
cout<<dist[t]<<endl;
}
int main()
{
while(cin>>n>>m)
{
solve();
}
return 0;
}