#include <stdio.h>
#define INFINITY 9999
#define MAX 10

void Dijkstra(int n,int G[][n], int startnode,int kraj) {
  int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];
for(i=0;i<n;i++)
{
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}
distance[startnode]=0;
visited[startnode]=1;
count=1;
while(count<n-1)
{
mindistance=INFINITY;
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{
mindistance=distance[i];
nextnode=i;
}
visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{
distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
}
count++;
}


    printf("%d",(distance[kraj]/100)+(distance[kraj]%100)/10);
}

int main() {
  int n,m,a,b,t,u,v;
    scanf("%d%d",&n,&m);
    int x[n][n];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            x[i][j]=0;
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&a,&b,&t);
        if(t==0){
        t=10;
        x[a-1][b-1]=t;
        x[b-1][a-1]=t;}
        else{
        t=100;
        x[a-1][b-1]=t;
        x[b-1][a-1]=t;}}

    scanf("%d%d",&u,&v);
    Dijkstra(n,x,u-1,v-1);
  return 0;
}