#include<iostream>#include<cstdio>#include<cstring>using namespace std;int cnt,st,ed,s,t,w,h[10005],dis[10005],stack[10005];int q[40005];struct Node{ int to,w,next;}edge[10005];//10005,1005void add(int s,int t,int v){ cnt++; edge[cnt].to=t; edge[cnt].w=v; edge[cnt].next =h[s]; h[s]=cnt;}int spfa(){ int head=1,tail=1; q[1]=st; while(head<=tail) { int u=q[head]; for(int i=h[u];i;i=edge[i].next) { int v=edge[i].to; if(edge[i].w+dis[u]<dis[v]) { dis[v]=edge[i].w+dis[u]; if(!stack[v]) { stack[v]=1; tail++; q[tail]=v; } } } }}int main(){ int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) { scanf("%d%d%d",&s,&t,&w); add(s,t,w); } scanf("%d%d",&st,&ed); memset(dis,1,sizeof dis); spfa(); cout<<dis[ed]<<endl;}