#include <bits/stdc++.h>
using namespace std;
struct node{
int v;
int w;
}now,tmp;
int n,m;
vector <node> Map[500001];
int vis[500001];
int d[500001];
void dijkstra(int s)
{
d[s]=0;
vis[s]=1;
now.v=s;
now.w=0;
queue <node> q;
q.push(now);
while(!q.empty())
{
now =q.front();
q.pop();
vis[now.v]=0;
int len=Map[now.v].size();
for(int i=0;i<len;i++)
{
tmp=Map[now.v][i];
if(d[tmp.v]>d[now.v]+tmp.w)
{
d[tmp.v]=d[now.v]+tmp.w;
if(!vis[tmp.v])
{
vis[tmp.v]=1;
q.push(tmp);
}
}
}
}
}
int main()
{
while(cin >> n >> m)
{
for(int i=1;i<=n;i++)
{
Map[i].clear();
}
while(m--)
{
int u,v,w;
scanf("%d %d %d",&u,&v,&w);
Map[u].push_back((node){v,w});
Map[v].push_back((node){u,w});
}
int s,e;
cin >> s >> e;
memset(d,0x3f3f3f,sizeof(d));
memset(vis,0,sizeof(vis));
dijkstra(s);
cout << d[e] << endl;
}
return 0;
}